Link to home
Start Free TrialLog in
Avatar of danomatic
danomaticFlag for United States of America

asked on

Lock down a drop down menu after selection?

Is there a way to lock down a drop down menu once the user has selected a value? In other words, put it into a read only after a selection has been made from the menu.
ASKER CERTIFIED SOLUTION
Avatar of glcummins
glcummins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Correct me if I am wrong, but doesn't disabling a form object make it inaccessible after the form is submitted?
Avatar of trifecta2k
trifecta2k

You're right!  Sorry about that, to use my solution you would have to enable the field before submitting.  
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or better yet, submit the values using Ajax?
<script language="javascript">
function disableDropdown() {
       document.bob.mySelect.disabled = true;
}
</script>

<form name="bob">
<select id="mySelect" onchange="javascript:disableDropdown()">
      <option selected="selected">Select One</option>
      <option value="1">Option One</option>
      <option value="2">Option Two</option>
      <option value="3">Option Three</option>
</select>
</form>
The trouble with disabling is remembering to enable afterwards.
The trouble with enabling is remembering to disable before submitting.
Avatar of danomatic

ASKER

ok, we will take a look at this. yes, and enabled is crucial because it submits a year to the database.
then have a hidden field like this
<script language="javascript">
function disableDropdown() {
       document.bob.year.value = document.bob.mySelect.value;
       document.bob.mySelect.disabled = true;
}
</script>
 
<form name="bob">
<input type="hidden" name="year" value="" />
<select id="mySelect" onchange="javascript:disableDropdown()">
      <option selected="selected">Select One</option>
      <option value="1">Option One</option>
      <option value="2">Option Two</option>
      <option value="3">Option Three</option>
</select>
</form>

Open in new window

Yes it was an objection I guess, I was just trying to give the author another possible solution since my previous post left the drop down disabled, after thinking about it would leave it useless, since once it's disabled it no longer sends the value.

So my other option sets the value of the drop down to a hidden field, disables the dropdown, so when submitted the chosen value will be passed to the processing page.
Avatar of b0lsc0tt
nplib,

Thanks for your participation here but I will leave my recommendation the same.  Your post at http:#20441953 can't be considered for cleanup.  Your first post http:#20059379 used code from one expert and the suggestion of another.  If credit had been given to the experts then things may be different since you did provide an example of what Badotz suggested.

The points you just mentioned in your post are good too but were pointed out by Glcummins earlier and were posted after the cleanup post.  The solution actually ends up being one suggested by the other experts above.

Thanks for your participation here though and your contribution to this site.  Keep up the good work and don't forget to read the previous posts and provide credit when you use something from another expert.  I hope this explanation helps but feel free to post your own recommendation of how this should be closed (not another solution but a recommendation of how to close this with the comments above my cleanup post).  The moderator who closes this will view your recommendation when he finalizes this.  Let me know if you have a question about anything I said.

b0lsc0tt
EE Cleanup Volunteer
Forced accept.

Computer101
EE Admin