Link to home
Create AccountLog in
Avatar of Pigdogmonster
Pigdogmonster

asked on

Disable <Select> box after onclick Javascript

Hi - Thanks for looking at my question.

I have a very simple form that consists of a select box and a button:

  <select name="USRMaterial_Type" id="USRMaterial_Type">
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        </select>

<input type="button" value="Submit" onClick="BTN.value='Auto';SUBBTN.value='User';theform.USRMaterial_Type.disabled=true;subm(this.form,'HiddenSubmitFrame');javascript:form.submit();">
       
I want the SELECT box to diable once the user clicks the button which is does but when the form submits it does not pass the selected value because the element is disabled!

My issue is this part:
USRMaterial_Type.disabled=true;

Is there a way to do this?

Thanks

PDM
Avatar of Ashish Patel
Ashish Patel
Flag of India image

Simple, create a hidden input field and before submit() pass the selected value of select into hidden field value and use it into other page from the hidden input field
Once s control is disabled, the value will not be sent with the form. Try creating a hidden control and then add a step to your onclick event to copy the value from the select to the hidden control BEFORE you disable.

LOL: I type too slow.!!
<input type="hidden" name="hUSRMaterial_Type" value="">
<input type="button" value="Submit" onClick="BTN.value='Auto';SUBBTN.value='User';theform.USRMaterial_Type.disabled=true;subm(this.form,'HiddenSubmitFrame');theform.hUSRMaterial_Type.value=theform.USRMaterial_Type.value;javascript:form.submit();">
ASKER CERTIFIED SOLUTION
Avatar of Ashish Patel
Ashish Patel
Flag of India image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Albert Van Halen
Just enable the selectbox again when you post the form
Avatar of Pigdogmonster
Pigdogmonster

ASKER

Thanks gents :)
espeicially asvforce as that is the solution I used.

I do however have a second part to this question that I hope you can help me with.

I have a 4 text box's but I only want 1 to appear on the screen until the user enters something in that text box.
What is the best way to do this?  I was thinking onclick but the user may not enter any text in the box and the 2nd would appear?

Any ideas?

Thanks again

PDM
try onchange, then in the function, check the control.value length to make sure it has content..


function unhide(oThis){
   if (oThis.length > 0)
       {   add your unhide code here }
  else
     { hide those suckers again }
 }

<input   id="text1" type=text  onchange="unhide(this);">