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 5 of 5
  1. #1
    New Coder
    Join Date
    Jan 2011
    Posts
    92
    Thanks
    8
    Thanked 0 Times in 0 Posts

    textbox should be deactivated when the dropdown selects

    Hi,

    i have a dropdown list where i have 3 options like
    Code:
    
        <tr>
                      <td><?php echo $entry_shippingtype; ?></td>
                      <td><select name="type">
                          <option value="free">Free Shipping</option>
                          <option value="flat">Flat Rate Shipping</option>
                         
                          <option value="weight">Weight Based Shipping</option>
                         
                          
                        </select></td>
                    </tr>
                    
                    
                    <tr>
                    <td><?php echo $entry_shippingamount; ?></td>
                    <td><input type="text" name="shippingamount" value="<?php echo $shippingamount; ?>" /></td>
                    </tr>
    When i select free shipping shippingamount textbox should be disabled. I dont know how to do it with javascript. Can someone help me please.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,853
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Code:
    <select name="type" onchange="var elm=document.getElementById('shippingamount');if(this.value=='free') elm.disable=true; else elm.disabled=false; ">
                          <option value="free">Free Shipping</option>
                          <option value="flat">Flat Rate Shipping</option>
                         
                          <option value="weight">Weight Based Shipping</option>
                         
                          
                        </select>
    Code:
    <input type="text" name="shippingamount" id="shippingamount" value="<?php echo $shippingamount; ?>" />
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Jan 2011
    Posts
    92
    Thanks
    8
    Thanked 0 Times in 0 Posts
    But its not taking. I have used like this. Am i doing wrong anywhere?

    Code:
    <tr>
                  <td><?php echo $entry_shippingtype; ?></td>
                  <td>
                 <select name="type" onchange="var elm=document.getElementById('shippingamount');if(this.value=='free') elm.disable=true; else elm.disabled=false; ">
                      <option value="free">Free Shipping</option>
                      <option value="flat">Flat Rate Shipping</option>
                     
                      <option value="weight">Weight Based Shipping</option>
                     
                      
                    </select></td>
                </tr>
                
                
                <tr>
                <td><?php echo $entry_shippingamount; ?></td>
                <td><input type="text" name="shippingamount" id="shippingamount" value="<?php echo $shippingamount; ?>" /></td>
                </tr>

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,992
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Typo.

    elm.disabled=true;

    It is your responsibility to die() if necessary….. - PHP Manual

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,458
    Thanks
    76
    Thanked 4,373 Times in 4,338 Posts
    More efficient:
    Code:
    <select name="type" onchange="this.form.shippingamount.disabled = (this.value=='free');">
    ...
    <input type="text" name="shippingamount" value="...whatever..." />
    No need for the id in the text field. And no need for a useless "if" test.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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