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

just change it to 3000!

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

instead of

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

on line 10

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

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>

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.

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

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

window.onbeforeunload = formReset();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.