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.val ue='User'; theform.US RMaterial_ Type.disab led=true;s ubm(this.f orm,'Hidde nSubmitFra me');javas cript: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
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';
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=
Is there a way to do this?
Thanks
PDM
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.val ue='User'; theform.US RMaterial_ Type.disab led=true;s ubm(this.f orm,'Hidde nSubmitFra me');thefo rm.hUSRMat erial_Type .value=the form.USRMa terial_Typ e.value;ja vascript:f orm.submit ();">
<input type="button" value="Submit" onClick="BTN.value='Auto';
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Just enable the selectbox again when you post the form
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
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);">
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);">