...

View Full Version : scripting issue



naveendk.55
08-25-2011, 12:28 PM
Hi, below code is only working in Firefox but not in Internet Explorer. Once I select YES from drop down list, then the next text box should be greyed out and the second should show value 10. This works in Firefox but not in Firefox .





<html>
<head>
<title>Untitled</title>
<script>


function enable()

{
document.myForm.textbox.disabled = false;
document.myForm.textbox2.value = 0;
}
function disable()

{

document.myForm.textbox.disabled = true;
document.myForm.textbox2.value = 10;
}

function value()
{
document.myForm.textbox2.value = 10;
}
</script>
</head>
<body>
<form name="myForm">
<table>
<tr>
<label> Do you accept </label>
<td>
<select name="na">
<option value="yes" onclick="disable()"> YES </option>
<option value="no" onclick="enable()"> NO </option>
<option value="NA" onclick="disable()"> NA </option>
</select>
<input type="text" name="textbox" value="" disabled>
<input type="text" name="textbox2" value="10" >
</td>
</tr>
<tr>
<td>

</td>
</tr>


</form>
</body>
</html>

DaveyErwin
08-25-2011, 12:51 PM
Use the onchange event


<html>
<head>
<title>Untitled</title>
<script>


function enable(){
document.myForm.textbox.disabled = false;
document.myForm.textbox2.value = 0;
}

function disable(){
document.myForm.textbox.disabled = true;
document.myForm.textbox2.value = 10;
}

function value(){
document.myForm.textbox2.value = 10;
}

function changed(el){
var sel = el.options[el.selectedIndex];
if (sel.value == "yes")disable();
if (sel.value == "no")enable();
if (sel.value == "na")disable();
}

</script>
</head>
<body>
<form name="myForm">
<table>
<tr>
<label> Do you accept </label>
<td>



<select name="na" onchange="changed(this)">
<option value="yes"> YES </option>
<option value="no" > NO </option>
<option value="NA" > NA </option>
</select>
<input type="text" name="textbox" value="" disabled>
<input type="text" name="textbox2" value="10" >
</td>
</tr>
<tr>
<td>

</td>
</tr>


</form>
</body>
</html>

if (sel.value == "na")disable();
should be ...
if (sel.value == "NA")disable();



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum