...

View Full Version : Enable a dropdown from value of a drop down



neilc
07-28-2006, 09:36 PM
I have two dropdowns (lets call them A and B), A is enabled and B is disabled. If I choose a specific option from A, then B will be enabled, but if I change the option on A to somthing else, B will turn disabled. Any ideas, I tried:



function EnableDisable(){
if ( document.myform.StandinPinCheckYes.value = "Risk Record")
{
document.myform.PinOffsetGeneration.disable=false
}
else
{
document.myform.PinOffsetGeneration.disable
}
}


and calling it from dropdown A by:


<select name="somthing" id="somthing" onchange="EnableDisable()">

RexxCrow
07-28-2006, 10:15 PM
Here is some good info:

http://www.tjhsst.edu/~dhyatt/superap/forms.html

http://www.hyper gurl.com/example2.html
(del the space between the hypergurl, it gets asterisked out for some reason.)

neilc
07-28-2006, 10:25 PM
Those are resources about HTML and Forms. How is those relavant to this problem?

vwphillips
07-28-2006, 10:49 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>

<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/

function Dis(obj){
if (!window['zxc'+obj.id]){ window['zxc'+obj.id]=''; }
var val=obj.value.split(',');
for (var zxc0=0;zxc0<val.length;zxc0++){
if (!window['zxc'+obj.id].match(val[zxc0])){ window['zxc'+obj.id]+=val[zxc0]+','; }
}
var enable=window['zxc'+obj.id].split(',');
for (var zxc1=0;zxc1<enable.length;zxc1++){
var eobj=document.getElementById(enable[zxc1]);
if (eobj){
eobj.removeAttribute('disabled');
}
}
for (var zxc2=0;zxc2<val.length;zxc2++){
eobj=document.getElementById(val[zxc2]);
if (eobj){
eobj.setAttribute('disabled','disabled');
}
}



}

/*]]>*/
</script>
</head>

<body>
<select id="S1" onchange="Dis(this);">
<option value="" >Option 0</option>
<option value="S2," >Option 1</option>
<option value="" >Option 2</option>
</select>

<select id="S2" >
<option value="" >Option 0</option>
<option value="" >Option 1</option>
<option value="" >Option 2</option>

</select>

</body>

</html>

neilc
08-01-2006, 04:49 PM
Thanks Vic, but that is the oposite of what I need.

I have the following code:



<script language="javascript">
function EnableDisable(){
if ( document.myform.StandinPinCheckYes.value = "Risk Record")
{
document.myform.PinOffsetGeneration.disabled=false
}
else
{
document.myform.PinOffsetGeneration.disabled
}
}
</script>


And Calling it like:



<select name="StandinPinCheckYes" id="StandinPinCheckYes" class="txtbox" onChange="EnableDisable()">
<option value="">&nbsp;</option>
<option value="Risk Record">Pin/Offset Included on Risk Record</option>
<option value="Track of Card">Pin/Offset Included on Track of Card</option>
</select>


to enable or disable:



<select name="PinOffsetGeneration" id="PinOffsetGeneration" class="txtbox">
<option value="">&nbsp;</option>
<option value="Negative Batch File">Negative Batch File</option>
<option value="Host Function">Host Function</option>
<option value="Online Message">Online Message</option>
</select>


Initially, the dropdown 'PinOffsetGeneration' is disabled from another function (called when the page loads) when 'Risk Record' is selected from the 'StandinPinCheckYes' dropdown, the 'PinOffsetGeneration' dropdown is enabled (but disabled again when a different option is selected from the 'StandinPinCheckYes' dropdown.

boeing747fp
08-01-2006, 05:37 PM
you need

if ( document.myform.StandinPinCheckYes.value == "Risk Record")

vwphillips
08-01-2006, 06:00 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>

<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/

function Dis(obj){
if (!window['zxc'+obj.id]){ window['zxc'+obj.id]=''; }
var val=obj.value.split(',');
for (var zxc0=0;zxc0<val.length;zxc0++){
if (!window['zxc'+obj.id].match(val[zxc0])){ window['zxc'+obj.id]+=val[zxc0]+','; }
}
var enable=window['zxc'+obj.id].split(',');
for (var zxc1=0;zxc1<enable.length;zxc1++){
var eobj=document.getElementById(enable[zxc1]);
if (eobj){
eobj.setAttribute('disabled','disabled');
}
}
for (var zxc2=0;zxc2<val.length;zxc2++){
eobj=document.getElementById(val[zxc2]);
if (eobj){
eobj.removeAttribute('disabled');
}
}
}

/*]]>*/
</script>
</head>

<body>
<select id="S1" onchange="Dis(this);">
<option value="" >Option 0</option>
<option value="S2," >Option 1</option>
<option value="" >Option 2</option>
</select>

<select id="S2" disabled="disabled" >
<option value="" >Option 0</option>
<option value="" >Option 1</option>
<option value="" >Option 2</option>

</select>

</body>

</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum