0

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

2
Contributors
6
Replies
7
Views
5 Years
Discussion Span
Last Post by lemur
0

just change it to 3000!

document.getElementById( 'rrpmax' ).selectedIndex = 3000;

instead of

document.getElementById( 'rrpmax' ).selectedIndex = 0;

on line 10

0

I tried it, for some reasons it s not working, especial with IE it s lot of mess.

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>
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.

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

0

what is the best way to call this function? can be something like below:

window.onbeforeunload = formReset();
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.