Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: scripting issue

  1. #1
    Regular Coder
    Join Date
    Aug 2011
    Posts
    101
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Question scripting issue

    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 .

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

  • #2
    Regular Coder
    Join Date
    Aug 2010
    Posts
    972
    Thanks
    19
    Thanked 212 Times in 210 Posts
    Use the onchange event

    Code:
    <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();
    Last edited by DaveyErwin; 08-25-2011 at 01:12 PM. Reason: another typo


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •