Load/Display page of last searched value Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience Should we burninate the [wrap] tag? The Ask Question Wizard is Live!What are valid values for the id attribute in HTML?Which “href” value should I use for JavaScript links, “#” or “javascript:void(0)”?How do I modify the URL without reloading the page?Set a default parameter value for a JavaScript functionHow can I get query string values in JavaScript?JavaScript chop/slice/trim off last character in stringSort array of objects by string property valueGet the size of the screen, current web page and browser windowHow can I refresh a page with jQuery?Redirect from an HTML page

Seeking colloquialism for “just because”

Fundamental Solution of the Pell Equation

What is the role of the transistor and diode in a soft start circuit?

Why did the Falcon Heavy center core fall off the ASDS OCISLY barge?

What LEGO pieces have "real-world" functionality?

Apollo command module space walk?

The logistics of corpse disposal

How to deal with a team lead who never gives me credit?

Why was the term "discrete" used in discrete logarithm?

Using audio cues to encourage good posture

Denied boarding although I have proper visa and documentation. To whom should I make a complaint?

Identifying polygons that intersect with another layer using QGIS?

How to react to hostile behavior from a senior developer?

Is it ethical to give a final exam after the professor has quit before teaching the remaining chapters of the course?

Why didn't this character "real die" when they blew their stack out in Altered Carbon?

Book where humans were engineered with genes from animal species to survive hostile planets

When a candle burns, why does the top of wick glow if bottom of flame is hottest?

How to tell that you are a giant?

Why do people hide their license plates in the EU?

How to call a function with default parameter through a pointer to function that is the return of another function?

How to find out what spells would be useless to a blind NPC spellcaster?

Error "illegal generic type for instanceof" when using local classes

English words in a non-english sci-fi novel

Why is my conclusion inconsistent with the van't Hoff equation?



Load/Display page of last searched value



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
Should we burninate the [wrap] tag?
The Ask Question Wizard is Live!What are valid values for the id attribute in HTML?Which “href” value should I use for JavaScript links, “#” or “javascript:void(0)”?How do I modify the URL without reloading the page?Set a default parameter value for a JavaScript functionHow can I get query string values in JavaScript?JavaScript chop/slice/trim off last character in stringSort array of objects by string property valueGet the size of the screen, current web page and browser windowHow can I refresh a page with jQuery?Redirect from an HTML page



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-2















Problem: submit form with "window.onload" create looping infinity.(form submitting non-stop)



When user visit page, I use the saved value to do searching once the page load, with



 window.onload = function() 

if (localStorage.getItem("datePicked"))
document.getElementById("searchPickDate").value = localStorage.getItem("datePicked");


document.getElementById("searchDateForm").submit();



searchDateForm form:



<form id='searchDateForm' name='searchDateForm' action='' method='POST'>
<input type='date' id='searchPickDate' name='searchPickDate' >
<input type='submit' value='Search' onclick="return searchDatebtn();" >
</form>


this is the code to save the search value:



function searchDatebtn() 
var asdf = document.getElementById("searchPickDate").value;
localStorage.setItem("datePicked", asdf);
return true;



I tried so many ways and digging the internet so hard but still failed to stop the looping. Any idea?
Thank you










share|improve this question



















  • 1





    It will loop because after the page loads, the form will submit, which refreshes the page, and when it loads again...well, you know what will happen. Why exactly would you submit the form right after the page loads? The form does not even have any values yet

    – Carl Binalla
    Mar 22 at 9:17












  • try using ajax to load the search item

    – Jaykant
    Mar 22 at 9:18











  • “Any idea? ” - same idea as always: Start by properly describing to us what you want to achieve here (instead of only showing us which wrong path you are on already.)

    – 04FS
    Mar 22 at 9:26











  • @CarlBinalla i edited post.. the form has its value when page onload.

    – wayne9003
    Mar 22 at 9:58











  • @nickzoum this is what I want to find out

    – wayne9003
    Mar 22 at 9:59

















-2















Problem: submit form with "window.onload" create looping infinity.(form submitting non-stop)



When user visit page, I use the saved value to do searching once the page load, with



 window.onload = function() 

if (localStorage.getItem("datePicked"))
document.getElementById("searchPickDate").value = localStorage.getItem("datePicked");


document.getElementById("searchDateForm").submit();



searchDateForm form:



<form id='searchDateForm' name='searchDateForm' action='' method='POST'>
<input type='date' id='searchPickDate' name='searchPickDate' >
<input type='submit' value='Search' onclick="return searchDatebtn();" >
</form>


this is the code to save the search value:



function searchDatebtn() 
var asdf = document.getElementById("searchPickDate").value;
localStorage.setItem("datePicked", asdf);
return true;



I tried so many ways and digging the internet so hard but still failed to stop the looping. Any idea?
Thank you










share|improve this question



















  • 1





    It will loop because after the page loads, the form will submit, which refreshes the page, and when it loads again...well, you know what will happen. Why exactly would you submit the form right after the page loads? The form does not even have any values yet

    – Carl Binalla
    Mar 22 at 9:17












  • try using ajax to load the search item

    – Jaykant
    Mar 22 at 9:18











  • “Any idea? ” - same idea as always: Start by properly describing to us what you want to achieve here (instead of only showing us which wrong path you are on already.)

    – 04FS
    Mar 22 at 9:26











  • @CarlBinalla i edited post.. the form has its value when page onload.

    – wayne9003
    Mar 22 at 9:58











  • @nickzoum this is what I want to find out

    – wayne9003
    Mar 22 at 9:59













-2












-2








-2








Problem: submit form with "window.onload" create looping infinity.(form submitting non-stop)



When user visit page, I use the saved value to do searching once the page load, with



 window.onload = function() 

if (localStorage.getItem("datePicked"))
document.getElementById("searchPickDate").value = localStorage.getItem("datePicked");


document.getElementById("searchDateForm").submit();



searchDateForm form:



<form id='searchDateForm' name='searchDateForm' action='' method='POST'>
<input type='date' id='searchPickDate' name='searchPickDate' >
<input type='submit' value='Search' onclick="return searchDatebtn();" >
</form>


this is the code to save the search value:



function searchDatebtn() 
var asdf = document.getElementById("searchPickDate").value;
localStorage.setItem("datePicked", asdf);
return true;



I tried so many ways and digging the internet so hard but still failed to stop the looping. Any idea?
Thank you










share|improve this question
















Problem: submit form with "window.onload" create looping infinity.(form submitting non-stop)



When user visit page, I use the saved value to do searching once the page load, with



 window.onload = function() 

if (localStorage.getItem("datePicked"))
document.getElementById("searchPickDate").value = localStorage.getItem("datePicked");


document.getElementById("searchDateForm").submit();



searchDateForm form:



<form id='searchDateForm' name='searchDateForm' action='' method='POST'>
<input type='date' id='searchPickDate' name='searchPickDate' >
<input type='submit' value='Search' onclick="return searchDatebtn();" >
</form>


this is the code to save the search value:



function searchDatebtn() 
var asdf = document.getElementById("searchPickDate").value;
localStorage.setItem("datePicked", asdf);
return true;



I tried so many ways and digging the internet so hard but still failed to stop the looping. Any idea?
Thank you







javascript html






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 22 at 10:30







wayne9003

















asked Mar 22 at 9:10









wayne9003wayne9003

259




259







  • 1





    It will loop because after the page loads, the form will submit, which refreshes the page, and when it loads again...well, you know what will happen. Why exactly would you submit the form right after the page loads? The form does not even have any values yet

    – Carl Binalla
    Mar 22 at 9:17












  • try using ajax to load the search item

    – Jaykant
    Mar 22 at 9:18











  • “Any idea? ” - same idea as always: Start by properly describing to us what you want to achieve here (instead of only showing us which wrong path you are on already.)

    – 04FS
    Mar 22 at 9:26











  • @CarlBinalla i edited post.. the form has its value when page onload.

    – wayne9003
    Mar 22 at 9:58











  • @nickzoum this is what I want to find out

    – wayne9003
    Mar 22 at 9:59












  • 1





    It will loop because after the page loads, the form will submit, which refreshes the page, and when it loads again...well, you know what will happen. Why exactly would you submit the form right after the page loads? The form does not even have any values yet

    – Carl Binalla
    Mar 22 at 9:17












  • try using ajax to load the search item

    – Jaykant
    Mar 22 at 9:18











  • “Any idea? ” - same idea as always: Start by properly describing to us what you want to achieve here (instead of only showing us which wrong path you are on already.)

    – 04FS
    Mar 22 at 9:26











  • @CarlBinalla i edited post.. the form has its value when page onload.

    – wayne9003
    Mar 22 at 9:58











  • @nickzoum this is what I want to find out

    – wayne9003
    Mar 22 at 9:59







1




1





It will loop because after the page loads, the form will submit, which refreshes the page, and when it loads again...well, you know what will happen. Why exactly would you submit the form right after the page loads? The form does not even have any values yet

– Carl Binalla
Mar 22 at 9:17






It will loop because after the page loads, the form will submit, which refreshes the page, and when it loads again...well, you know what will happen. Why exactly would you submit the form right after the page loads? The form does not even have any values yet

– Carl Binalla
Mar 22 at 9:17














try using ajax to load the search item

– Jaykant
Mar 22 at 9:18





try using ajax to load the search item

– Jaykant
Mar 22 at 9:18













“Any idea? ” - same idea as always: Start by properly describing to us what you want to achieve here (instead of only showing us which wrong path you are on already.)

– 04FS
Mar 22 at 9:26





“Any idea? ” - same idea as always: Start by properly describing to us what you want to achieve here (instead of only showing us which wrong path you are on already.)

– 04FS
Mar 22 at 9:26













@CarlBinalla i edited post.. the form has its value when page onload.

– wayne9003
Mar 22 at 9:58





@CarlBinalla i edited post.. the form has its value when page onload.

– wayne9003
Mar 22 at 9:58













@nickzoum this is what I want to find out

– wayne9003
Mar 22 at 9:59





@nickzoum this is what I want to find out

– wayne9003
Mar 22 at 9:59












4 Answers
4






active

oldest

votes


















1














Submit will send you to the url you have set in the form action="" attribute
in your case the attribuie is empty, so the browser assumes it is your current url and it will take you to that url



Submit is kind of bad for user experience
In your case you should retrieve your last picked date
and use it to fetch last searches from server with an ajax request






share|improve this answer






























    0














    Instead of submit your form call directly your function.



    window.onload = function() 
    searchDatebtn();



    And if you don't want to refresh the page, return false in your search function



    function searchDatebtn() 
    var asdf = document.getElementById("searchPickDate").value;
    localStorage.setItem("datePicked", asdf);
    return false;






    share|improve this answer
































      0














      Try to check if the date is already stored in the localStorage to stop the infinite loop :



      window.onload = function() 
      if( localStorage.getItem("datePicked") != null )
      document.getElementById("searchDateForm").submit();







      share|improve this answer






























        0














        Try this code.



        window.onload = function() 
        var searchKey = localStorage.getItem('key');
        if(searchKey != '')
        document.getElementById("searchDateForm").submit();
        localStorage.setItem('key', '')







        share|improve this answer























          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55296213%2fload-display-page-of-last-searched-value%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          4 Answers
          4






          active

          oldest

          votes








          4 Answers
          4






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Submit will send you to the url you have set in the form action="" attribute
          in your case the attribuie is empty, so the browser assumes it is your current url and it will take you to that url



          Submit is kind of bad for user experience
          In your case you should retrieve your last picked date
          and use it to fetch last searches from server with an ajax request






          share|improve this answer



























            1














            Submit will send you to the url you have set in the form action="" attribute
            in your case the attribuie is empty, so the browser assumes it is your current url and it will take you to that url



            Submit is kind of bad for user experience
            In your case you should retrieve your last picked date
            and use it to fetch last searches from server with an ajax request






            share|improve this answer

























              1












              1








              1







              Submit will send you to the url you have set in the form action="" attribute
              in your case the attribuie is empty, so the browser assumes it is your current url and it will take you to that url



              Submit is kind of bad for user experience
              In your case you should retrieve your last picked date
              and use it to fetch last searches from server with an ajax request






              share|improve this answer













              Submit will send you to the url you have set in the form action="" attribute
              in your case the attribuie is empty, so the browser assumes it is your current url and it will take you to that url



              Submit is kind of bad for user experience
              In your case you should retrieve your last picked date
              and use it to fetch last searches from server with an ajax request







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Mar 22 at 9:33









              Gabriel IlisoiGabriel Ilisoi

              92




              92























                  0














                  Instead of submit your form call directly your function.



                  window.onload = function() 
                  searchDatebtn();



                  And if you don't want to refresh the page, return false in your search function



                  function searchDatebtn() 
                  var asdf = document.getElementById("searchPickDate").value;
                  localStorage.setItem("datePicked", asdf);
                  return false;






                  share|improve this answer





























                    0














                    Instead of submit your form call directly your function.



                    window.onload = function() 
                    searchDatebtn();



                    And if you don't want to refresh the page, return false in your search function



                    function searchDatebtn() 
                    var asdf = document.getElementById("searchPickDate").value;
                    localStorage.setItem("datePicked", asdf);
                    return false;






                    share|improve this answer



























                      0












                      0








                      0







                      Instead of submit your form call directly your function.



                      window.onload = function() 
                      searchDatebtn();



                      And if you don't want to refresh the page, return false in your search function



                      function searchDatebtn() 
                      var asdf = document.getElementById("searchPickDate").value;
                      localStorage.setItem("datePicked", asdf);
                      return false;






                      share|improve this answer















                      Instead of submit your form call directly your function.



                      window.onload = function() 
                      searchDatebtn();



                      And if you don't want to refresh the page, return false in your search function



                      function searchDatebtn() 
                      var asdf = document.getElementById("searchPickDate").value;
                      localStorage.setItem("datePicked", asdf);
                      return false;







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Mar 22 at 9:19

























                      answered Mar 22 at 9:14









                      R3tepR3tep

                      8,28382962




                      8,28382962





















                          0














                          Try to check if the date is already stored in the localStorage to stop the infinite loop :



                          window.onload = function() 
                          if( localStorage.getItem("datePicked") != null )
                          document.getElementById("searchDateForm").submit();







                          share|improve this answer



























                            0














                            Try to check if the date is already stored in the localStorage to stop the infinite loop :



                            window.onload = function() 
                            if( localStorage.getItem("datePicked") != null )
                            document.getElementById("searchDateForm").submit();







                            share|improve this answer

























                              0












                              0








                              0







                              Try to check if the date is already stored in the localStorage to stop the infinite loop :



                              window.onload = function() 
                              if( localStorage.getItem("datePicked") != null )
                              document.getElementById("searchDateForm").submit();







                              share|improve this answer













                              Try to check if the date is already stored in the localStorage to stop the infinite loop :



                              window.onload = function() 
                              if( localStorage.getItem("datePicked") != null )
                              document.getElementById("searchDateForm").submit();








                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Mar 22 at 9:20









                              Zakaria AcharkiZakaria Acharki

                              57.2k134471




                              57.2k134471





















                                  0














                                  Try this code.



                                  window.onload = function() 
                                  var searchKey = localStorage.getItem('key');
                                  if(searchKey != '')
                                  document.getElementById("searchDateForm").submit();
                                  localStorage.setItem('key', '')







                                  share|improve this answer



























                                    0














                                    Try this code.



                                    window.onload = function() 
                                    var searchKey = localStorage.getItem('key');
                                    if(searchKey != '')
                                    document.getElementById("searchDateForm").submit();
                                    localStorage.setItem('key', '')







                                    share|improve this answer

























                                      0












                                      0








                                      0







                                      Try this code.



                                      window.onload = function() 
                                      var searchKey = localStorage.getItem('key');
                                      if(searchKey != '')
                                      document.getElementById("searchDateForm").submit();
                                      localStorage.setItem('key', '')







                                      share|improve this answer













                                      Try this code.



                                      window.onload = function() 
                                      var searchKey = localStorage.getItem('key');
                                      if(searchKey != '')
                                      document.getElementById("searchDateForm").submit();
                                      localStorage.setItem('key', '')








                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Mar 22 at 9:23









                                      Prabu samvelPrabu samvel

                                      1




                                      1



























                                          draft saved

                                          draft discarded
















































                                          Thanks for contributing an answer to Stack Overflow!


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid


                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.

                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function ()
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55296213%2fload-display-page-of-last-searched-value%23new-answer', 'question_page');

                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown







                                          Popular posts from this blog

                                          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                                          용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                                          155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해