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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Database generated list boxes 1

Status
Not open for further replies.

mattys

Programmer
May 1, 2001
35
GB
Hi

I have a couple of dynamically generated list boxes on this page If you select a criteria, in either, or both, but don't carry out a search and hit clear, they clear. However, if you select either, or both and carry out a search and then decide to carry out a completely different search, based on different criteria, the clear button does not clear the selected criteria.

Any ideas how this can be resolved?

Help and advice greatly appreciated.

Regards

Matt
 
You will need to reset both list boxes on the onClick event of the Clear button. Try something like this. (Strictly this would belong in the Javascript forum - Forum216)
Code:
<SCRIPT language="JAVASCRIPT">
function resetForm()
{
  document.frmSearch.Towns.selectedIndex=0;
  document.frmSearch.Locations.selectedIndex=0;
}
</SCRIPT>
...
...
...
...
<input type="reset" name="B2" class="buttons" value="Clear" onClick="resetForm();">
The reason the Clear button is currently not clearing the FORM is because it is intended to reset the form to its original state when the page was loaded. Since the page is loaded with the previous values selected, that is what it will reset to.

Tony
________________________________________________________________________________
 
Thanks FesterSXS

Seems to make sense, sorry for not submitting to javascript forum.

I have tried the above and added the javascript bit, but it still doesn't seem to work. Can you let me know exactly where to place the Javascript?

Cheers

Matt
 
try changing the RESET button to a BUTTON
Code:
<INPUT type="button" name="B2" class="buttons" value="Clear" onClick="resetForm();">

Tony
________________________________________________________________________________
 
Thanks FesterSXS

Strange. What is happening now is that if nothing is selected and you hit 'clear', it selects the top two criteria. If you have critaria selected, before or after search, when you hit 'clear' it also selects top two criteria??

Matt
 
also - change the button back to RESET type. This will ensure that the list scrolls back to the top.

Tony
________________________________________________________________________________
 
FesterSXS

Tried this and just does the same as before, but goes to critera 2, or nothing at all.

Hmmmmm...

Matt
 
FesterSXS

Ignore last response, sent before I got your last response. Have tried with reset and if you select criteria, but don't search and then clear, it clears, but if you do a search and then try and clear it doesn't.

Matt
 
whoooa, getting crossed wires, will now try -1, not 1
 
ok - put it back to a BUTTON instead of RESET and add these at the top of your function
Code:
function resetForm()
{
[b]  document.frmSearch.Towns.selectedIndex=0;
  document.frmSearch.Locations.selectedIndex=0;[/b]
  document.frmSearch.Towns.selectedIndex=-1;
  document.frmSearch.Locations.selectedIndex=-1;
}

Tony
________________________________________________________________________________
 
FesterSXS

Thanks for your help, it does work with -1 and 'Button' (not reset). Much, much, mcuh appreciated!! will rate highly.

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top