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;
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
add a comment |
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
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
add a comment |
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
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
javascript html
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
add a comment |
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
add a comment |
4 Answers
4
active
oldest
votes
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
add a comment |
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;
add a comment |
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();
add a comment |
Try this code.
window.onload = function()
var searchKey = localStorage.getItem('key');
if(searchKey != '')
document.getElementById("searchDateForm").submit();
localStorage.setItem('key', '')
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
answered Mar 22 at 9:33
Gabriel IlisoiGabriel Ilisoi
92
92
add a comment |
add a comment |
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;
add a comment |
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;
add a comment |
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;
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;
edited Mar 22 at 9:19
answered Mar 22 at 9:14
R3tepR3tep
8,28382962
8,28382962
add a comment |
add a comment |
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();
add a comment |
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();
add a comment |
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();
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();
answered Mar 22 at 9:20
Zakaria AcharkiZakaria Acharki
57.2k134471
57.2k134471
add a comment |
add a comment |
Try this code.
window.onload = function()
var searchKey = localStorage.getItem('key');
if(searchKey != '')
document.getElementById("searchDateForm").submit();
localStorage.setItem('key', '')
add a comment |
Try this code.
window.onload = function()
var searchKey = localStorage.getItem('key');
if(searchKey != '')
document.getElementById("searchDateForm").submit();
localStorage.setItem('key', '')
add a comment |
Try this code.
window.onload = function()
var searchKey = localStorage.getItem('key');
if(searchKey != '')
document.getElementById("searchDateForm").submit();
localStorage.setItem('key', '')
Try this code.
window.onload = function()
var searchKey = localStorage.getItem('key');
if(searchKey != '')
document.getElementById("searchDateForm").submit();
localStorage.setItem('key', '')
answered Mar 22 at 9:23
Prabu samvelPrabu samvel
1
1
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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