By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,310 Members | 1,165 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,310 IT Pros & Developers. It's quick & easy.

Convert the option value, using textbox value

P: 1
Hi,
Can you please help me, I want to write a dropdown box that have an option 'Other' but when the Other is selected my textbox need to be enable and take the textbox value as an output instead of Other.



[HTML]<script language=javascript type="text/javascript">
function pairSelectToOther(whichCtrl,otherCtrl,otherStr)
{
if(whichCtrl.options[whichCtrl.selectedIndex].value == otherStr)
{
otherCtrl.disabled = false;
alert("Please provide specification")
}
else
{
otherCtrl.disabled = true;
//if the guy selects some other value in the select box , after inputting into the
//other textbox, the value shouldn't get posted.
otherCtrl.value = "";
}
return true;
}
</script>

&nbsp;&nbsp;
<select id="selectlist" name="role" style="font-family: Arial; width:200px;" onChange="return pairSelectToOther(this,Reason_Other,'Other')">
<option value="Lead Arrager">Lead Arrager</option>
<option value="Joint Lead Arrager">Joint Lead Arrager</option>
<option value="Dealer">Dealer</option>
<option value="Finacial Advisor">Finacial Advisor</option>
<option value="Joint Finacial Advisor">Joint Finacial Advisor</option>
<option value="Lender">Lender</option>
<option value="Lead Manager">Lead Manager</option>
<option value="Joint Manager">Joint Manager</option>
<option value="Underwriter">Underwriter</option>
<option value="Other">Other</option>
</select>
<% //Done Role Changes (Other ) %>
<br>
<br>
<b></b><i style="font-family: Arial; color: #00376c;"><font size="2">(if <b>'Other'</b>, please specify)</font></i></b>
<br>
&nbsp;&nbsp;

<input style="font-family: Arial;" type="text" name="Reason_Other" disabled size="38">[/HTML]
Feb 19 '07 #1
Share this Question
Share on Google+
2 Replies

100+
P: 157
Hi,

I tested your code, it is working,

If I'm not wrong you need that when the user selects 'Other' option from the Dropdown you want the textfield to be enabled or else not which is happening through your code.

If you want the value typed in the textfield you can get it by saying -

document.WhateverYour FormName.Reason_Other.value ;

OR

give your textfield an id and then you can access the text by using getElementById() i.e -

document.getElementById("WhateverIdOfTheTextField" ).value

Is this your requirement or something else?
Feb 19 '07 #2

acoder
Expert Mod 15k+
P: 16,027
Hi,
Can you please help me, I want to write a dropdown box that have an option 'Other' but when the Other is selected my textbox need to be enable and take the textbox value as an output instead of Other.
There are two ways you can deal with this. One is to do all of it on the server side and don't depend on the client-side, i.e. check for 'Other', if found, instead of using the select dropdown value, use the textbox value.

The other method (which you are probably looking for) is actually quite simple. Just set the value of the 'Other' option to the textbox value. Then that will be posted to your server-side script.
Feb 19 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.