[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Disable <Select> box after onclick Javascript

Posted on 2007-10-04
9
Medium Priority
?
2,549 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:Pigdogmonster
8 Comments
 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20014131
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
0
 
LVL 4

Expert Comment

by:lrygiel
ID: 20014134
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.

0
 
LVL 4

Expert Comment

by:lrygiel
ID: 20014138
LOL: I type too slow.!!
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20014142
<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();">
0
 
LVL 23

Accepted Solution

by:
Ashish Patel earned 200 total points
ID: 20014159
<input type="button" value="Submit" onClick="BTN.value='Auto';SUBBTN.value='User';theform.hUSRMaterial_Type.value=theform.USRMaterial_Type.value;theform.USRMaterial_Type.disabled=true;subm(this.form,'HiddenSubmitFrame');javascript:form.submit();">
0
 
LVL 19

Expert Comment

by:Albert Van Halen
ID: 20014213
Just enable the selectbox again when you post the form
0
 

Author Comment

by:Pigdogmonster
ID: 20015492
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
0
 
LVL 4

Expert Comment

by:lrygiel
ID: 20015611
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);">
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question