Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reset Form to default values AFTER I've removed options

Status
Not open for further replies.

Lori713

Programmer
Feb 4, 2008
4
US
Howdy,

I'm trying to set up my form so that the user can click on a Reset button to reset the form to the original values that were in the select boxes. However, it appears that while this works with most of my select boxes, there are a few that it isn't working on.

I have a select box that is dynamically changed based on some selections in other boxes using the following code, so some options are removed.
Code:
function updateProgList()
{
// Updates the Program list by removing funding groups not selected
var progElement = document.getElementsByTagName('select')['prog2'];
var i = 0;
var k = 0;

// For each item in the funding group that was NOT previously selected...
for ( k = 0; k < modFundsArray.length; k++ )
    { // ...  for each item in the Program list, remove the programs that begin
      //      with the current funding group code being passed to it via 'for'
      i = 0;  //  reset to zero so it will go back through entire prog list again
      while ( i < progElement.length )
            { if   ( progElement[i].value.substr(0,2) == modFundsArray[k] )
                   { progElement.removeChild(progElement[i]); }
              else { i++; }
            }
    }
}

After the select boxes are updated to reflect choices they can make, the user will be able to either submit the form or reset the form back to its original state (and all original options are available again).

Unfortunately, my reset button isn't resetting the boxes that had options removed from them. The following is my code for the Continue and Reset buttons (Continue updates the various select boxes; Reset should put the form back to its original state):

Code:
<td class="vert" width="25%">
<input type="button" name="bmscont" id="bmscont" value="Continue"
       onclick="hideShowContinue('14_summary');"/>
<input type="reset" name="myreset" id="myreset" value="Reset" />
</td>
</tr>

I think I must be missing something somewhere but I'm not sure what it is. Is it possible to reset ALL select boxes, even ones where you have removed options previously?

Thanks!

Lori
 
I think I must be missing something somewhere but I'm not sure what it is. Is it possible to reset ALL select boxes, even ones where you have removed options previously?

Not with the reset control you're using. Once those elements have been removed from the dropdowns the reset form method will not return them. You have 2 options:

[ol][li]Store all the elements in each dropdown in an array when the page loads. Also, store all initial form values in another array when the page loads. Then, create a custom reset control to repopulate the dropdowns to their original values, and afterwards set the active value for each form element to the values in the initial value array[/li]
[li] This is the easy option and probably the one I would go with: just reload the page[/li][/ol]

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Thank you, kaht! I had originally had the Reset button reload the page, but it takes a bit of time to do that with all the preloaded select boxes (it took more time than the customers would tolerate), so I will need to go with option 1.

I will now put my efforts into creating arrays and such.

Cheers!

Lori
 
I will now put my efforts into creating arrays and such.

I'm sorry... that does not sound very fun [sad]

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top