Start New Discussion Reply to this Discussion Reset function
Hi there, I wrote code that reset search settings, code is:
function formReset()
{
var fields = document.getElementsByTagName( "input" );
for ( i = 0; i < fields.length; i++ )
{
if ( fields[ i ].type == "checkbox" )
fields[ i ].checked = false;
}
document.getElementById( 'rrpmin' ).selectedIndex = 0;
document.getElementById( 'rrpmax' ).selectedIndex = 0;
eraseCookie( _cookieName );
fieldClick();
}
but what I need to change is after reset set up rrpmax as 3000, not 0. any idea how to do it? and one more thing, what is the best way to clear form when user leave page?
Thanks for any hints
10 Months Ago
Last Updated
Related Article: JQuery loader
is a solved JavaScript / DHTML / AJAX discussion thread by MWEB that has 5 replies and was last updated 6 months ago.
lemur
Light Poster
36 posts since May 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
just change it to 3000!
document.getElementById( 'rrpmax' ).selectedIndex = 3000;
instead of
document.getElementById( 'rrpmax' ).selectedIndex = 0;
on line 10
rvcT
Newbie Poster
5 posts since Jun 2012
Reputation Points: 0
Solved Threads: 1
Skill Endorsements: 0
I tried it, for some reasons it s not working, especial with IE it s lot of mess.
lemur
Light Poster
36 posts since May 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
check javascript console in ur browser the form reset and setting option with 'selectedIndex' is absolutely valid i tested it even with ie6 and it worked
the code i tested:
<html>
<head>
<script type="text/javascript">
function formReset()
{
var fields = document.getElementsByTagName( "input" );
for ( i = 0; i < fields.length; i++ )
{
if ( fields[ i ].type == "checkbox" )
fields[ i ].checked = false;
}
document.getElementById( 'rrpmax' ).selectedIndex = 1;//test with 0 or 2 "the availabe options"it will work
}
</script>
</head>
<body>
<input type="button" value="reset" onclick="formReset()"/>
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<select id="rrpmax">
<option>a</option>
<option>b</option>
<option>c</option>
</select>
</body>
</html>
rvcT
Newbie Poster
5 posts since Jun 2012
Reputation Points: 0
Solved Threads: 1
Skill Endorsements: 0
Ok, thanks, I try tomorrow. And maybe you have some idea, how to clear (reset) form when user leaveing page so fucntion must be call without reset click. I got one form for many pages, so first selected is going to anoher page. Thats no good.
lemur
Light Poster
36 posts since May 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
if u have may pages with forms i guess that the user will leave page A to page B with a submit or similar button "ie: the user will need to trigger an event to leave the page" so u can call reset function before submission or what ever event u depend on to leave page
rvcT
Newbie Poster
5 posts since Jun 2012
Reputation Points: 0
Solved Threads: 1
Skill Endorsements: 0
what is the best way to call this function? can be something like below:
window.onbeforeunload = formReset();
lemur
Light Poster
36 posts since May 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
© 2013 DaniWeb® LLC
Page rendered in 0.0768 seconds
using 2.7MB