It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

enable textbox if others is selected in drop down list

enable textbox if others is selected in drop down list

Postby sundarraj_mca on Thu May 15, 2008 10:07 am

hai developers,

in my form i have a drop down menu in which others option is stated at last.

if user clicks others option i want to enable the text box below which is disabled by default.
sundarraj_mca
 
Posts: 22
Joined: Wed May 14, 2008 5:06 am

Postby rangana on Thu May 15, 2008 11:03 am

Give your select box and id. For example:
Code: Select all
<select id="myselect">


..Now if you're done giving it an id, give your input box and id too. Example would be:
Code: Select all
<input type="text" disable="disable" id="myinput">


...Now when you're finished doing thosse, you need to decide when you want the even to trigger..either onchange (option box is change) or onclick (triggered by a button).

If you want the earlier, then this code would suffice, using the id's i've given as example.
Code: Select all
window.onload=function()
{
var select=document.getElementById('myselect');
var inps=document.getElementById('myinput');
select.onchange=function()
{
switch(select.value)
{
case 'others':
inps.disabled=false;
break;
}
}
}


Note that your other's option box value should be others, or else, change this part to what your value is:
Code: Select all
case 'others':


IF you want an event triggered via onclick, don't hesitate to come back. ;)
See if it helps :)
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines


Who is online

Users browsing this forum: No registered users and 4 guests