Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

disable/enable items

Status
Not open for further replies.

ttuser4

MIS
Jun 19, 2008
147
0
0
CA
hi,

i have two selects which i want disable/enable based on selected value of another select:

<tr>
<td><b>8. Motor:</b> </td>
<td> <select size="1" name="motor" id="motor" onChange="calc2(this.form);">
<?php
if($md=='lb'){
echo ' <option selected value="0"> </option>';
echo ' <option value="120"> 120V </option>';
echo ' <option value="220"> 220V </option>';
} else {
echo ' <option selected value="0"> </option>';
echo ' <option value="220"> 220V </option>';
echo ' <option value="120"> 120V </option>';
}
?>
<option value="none"> None </option>
</select>
</td>
<td>Select motor.</td>
</tr>
<tr>
<td><b>9. Remote control:</b> </td>
<td> <select size="1" name="rc" id="rc">
<option selected value="0"> None </option>
<option value="1"> 1 </option>
<option value="2"> 2 </option>
<option value="3"> 3 </option>
</select>
</td>
<td>Select number of remote controls.</td>
</tr>
<tr>
<td><b>10. Wall switch:</b> </td>
<td> <select size="1" name="ws" id="ws">
<option selected value="0"> None </option>
<option value="1"> 1 </option>
<option value="2"> 2 </option>
<option value="3"> 3 </option>
<option value="4"> 4 </option>
<option value="5"> 5 </option>
</select>
</td>
<td>Select number of wall switches.</td>
</tr>


javascrip:

function calc2(form){

var mtr = document.getElementById('motor').value;

if (mtr==120 || mtr==220) {
document.form.rc.disabled=false;
document.form.ws.disabled=false;
} else {
document.form.rc.disabled=true;
document.form.ws.disabled=true;
}

if (mtr != "none") {

if(form.units[0].checked) {
var span=parseFloat(form.span.value);
var width=parseFloat(form.width.value);
} else {
var span=(parseFloat(form.span.value)*2.54)*10;
var width=(parseFloat(form.width.value)*2.54)*10;
}

var slope1=String(parseFloat(form.slope.value)).substring(0,1);
var slope2=String(parseFloat(form.slope.value)).substring(3,1);

var numbays=Math.ceil((width - 80) / 1080);
var numbays=numbays+parseFloat(form.eb.value);

var baywidth=(width - 32)/numbays;
var height=span*(Math.sqrt((slope1*slope1)+(slope2*slope2))/slope2);

var barea=(height/1000)*(baywidth/1000);
//alert("bay area is: " + barea + " m2");

var lim=0;
var glz = document.getElementById('glazing').value;

if (glz == "pc") {
lim=10;
} else {
lim=7.5;
}

if(barea > lim ) {
alert("Please change input value, bay area is over limit: " + barea + " m2");
}
}
}

javascript function does the rest of calculations, but this part is not working:

var mtr = document.getElementById('motor').value;

if (mtr==120 || mtr==220) {
document.form.rc.disabled=false;
document.form.ws.disabled=false;
} else {
document.form.rc.disabled=true;
document.form.ws.disabled=true;
}

can you please help me to fix it?
 
There are many things missing in your html, that could cause errors, so I can't tell which ones you left off deliberately, and which ones are really there.

So the first thing to check is if you have any errors. Both IE and FF offer error consoles so you can check you JS is correct. For IE its the yellow shield icon on the bottom right corner. If you double click it it should bring up the console if there are any errors.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
my mistake, the error was in the form name.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top