Forum Moderators: open

Message Too Old, No Replies

Greying out control problem

Posted variable gets nuked

         

rich_b

2:23 pm on Aug 17, 2005 (gmt 0)

10+ Year Member



I have a simple form which is automatically submitted when a user chooses an option from a select box. This worked great. What I'd like to do now is grey out the select box once the user has clicked on it so the user can't select it again until after the page has refreshed.

I added in the following line to function 'setFormSubmitMarker' that gets called when the user selects an option:

frm.selOption.disabled=true;

This greyed out the select box ok but stopped the value of the select from being posted (I've removed the PHP code that I used to read the posted variable). It seems as though disabling the select box also prevents the form from posting the value of the select box? I tried swapping the order of the two lines in the function function 'setFormSubmitMarker' but that didn't work. Please can anyone suggest a solution?

Here's the code:

<html>
<body>
<script>
function setFormSubmitMarker(frm,valu) {
frm.selOption.disabled=true;
frm.whichSubmit.value=valu;
}
</script>
<form method="POST">
<input type="hidden" name="whichSubmit" value="">
<select name="selOption" onchange="setFormSubmitMarker(this.form,'selectmenu');this.form.submit();">
<option value="NULL">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
<input type="submit" onclick="setFormSubmitMarker(this.form,'submitbutton')">
</form>
</body>
</html>

kaled

8:15 pm on Aug 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You must disable the control AFTER calling form.submit();

Having said that, browsers are multithreaded (i.e. tasks may be carried out concurrently rather than sequentially) so this may not work. In this case, you must use a delay, of, say 1000 milliseconds.

setTimeout("frm.selOption.disabled=true",1000);

Kaled.

rich_b

8:57 pm on Aug 17, 2005 (gmt 0)

10+ Year Member



Man, you rock! Thanks very much! I spent 4 hours trying to do that and not even Google had the answer. Much appreciated!