Jump to content

Scripting issue.. help


naveendk.55

Recommended Posts

Hi below form works in Firefox but not in Internet Explorer.  Once I select YES the first text box should be disabled and the value should be 10. Once I select NO, then the second box should be enabled and third box value should be 0. This works normally in Firefox but not in Internet Explorer 7.

 


<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>


Link to comment
https://forums.phpfreaks.com/topic/245672-scripting-issue-help/
Share on other sites

The following modification works fine.

I substituted the "onClick" function with a "onChange", and removed the JS value() function since there was no use for it.

 

<html>
<head>
<title>Untitled</title>
<script language="JavaScript">
function process(val) {
if(val == "no") {
	document.myForm.textbox.disabled = false;
	document.myForm.textbox2.value = 0;
}else{
	document.myForm.textbox.disabled = true;
	document.myForm.textbox2.value = 10;
}
}
</script>
</head>
<body>
<form name="myForm">
    <table>
        <tr> 
    <label> Do you accept </label> 
    <td> 
    <select name="na" onChange="process(this.value);">
        <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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.