Reset on Load

Results 1 to 2 of 2

Thread: Reset on Load

  1. #1
    Join Date
    Dec 1969

    Default Reset on Load

    I want to create an onload function. This function must reset the values in a form to "All".I came across this script. The problem that I have it clears all the values to blank. <BR>}<BR>function Reset() {<BR>document.forms[0].elements[0].value = "";<BR>document.forms[0].elements[1].value = "";<BR>document.forms[0].elements[2].value = ""; <BR>document.forms[0].elements[3].value = "";<BR>document.forms[0].elements[4].value = "";<BR>document.forms[0].elements[5].value = "";<BR>document.forms[0].elements[6].value = "";<BR>document.forms[0].elements[7].value = "";<BR>document.forms[0].elements[0].focus();<BR>}<BR><BR>When I change the "" to "All" it only changes the first fields value to "All". The first field is a text field and the rest of the fields are option select fields. Is there a way that I can change the values of the select fields to All using the above script ?<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Reset on Load

    You need a helper function<BR><BR>function resetSelect(oSelect, sValue)<BR>{<BR> for(var i=0; i&#060;oSelect.options.length; i++)<BR> {<BR> if(oSelect.options[i].value == sValue){ oSelect.options[i].selected = true; return true; }<BR> }<BR> return false;<BR>}<BR><BR>Then, use your function but modify it:<BR><BR>function Reset()<BR>{<BR> document.forms[0].elements[0].value = "All";<BR> resetSelect(document.forms[0].elements[1], "All");<BR> // ...<BR>}<BR><BR>Bear in mind that referencing forms and their elements ordinally is probably a bad idea - if the form changes (or the order of items changes) then your script&#039;s going to fall flat on its face.<BR><BR>Also, if you&#039;re going to be doing web development, I suggest some decent books on SQL, JavaScript and ASP.<BR><BR>Craig.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts