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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question onchange dropdown value hide row

    Hi,

    I am very new to javascript. I tried to hide row on changing dropdown select
    value. Please correct me where I am mistaking. Any hint will be highly appreciated my code is:-

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <script language="javascript" type="text/javascript">
    function showHide(type){
    if(type == 'code'){
    document.getElementById('trText').style.display = 'block';
    else{
    document.getElementById('trText').style.display = 'none';
    }


    }

    </script>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
    </head>

    <body>
    <form name="form1" id="form1" method="post" action="">
    <p>&nbsp;</p>
    <table width="100%" border="1" cellspacing="0" cellpadding="0">
    <tr>
    <td><select name="select" onchange="showHide(this.Value)">
    <option value="0">abc</option>
    <option value="1">def</option>
    </select></td>
    </tr>
    <tr id="trText" style="display:none ">
    <td><input type="text" name="textfield" /></td>
    </tr>
    </table>
    <p>&nbsp; </p>
    </form>
    </body>

    Note: The error I am receieving is object is expected. Kindly correct me where exactly im mistaking..

  • #2
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by ahussain View Post
    Note: The error I am receieving is object is expected. Kindly correct me where exactly im mistaking..
    Code:
    onchange="showHide(this.Value)"
    Should be
    Code:
    onchange="showHide(this.value)"
    Also the select is going to pass only "0" or "1", but showHide is expecting 'code'.

  • #3
    Regular Coder
    Join Date
    Feb 2005
    Posts
    679
    Thanks
    0
    Thanked 16 Times in 15 Posts
    Also, your if/else is missing a '}'
    Code:
    if(type == 'code'){
    document.getElementById('trText').style.display = 'block';
    } else {
    document.getElementById('trText').style.display = 'none';
    }


  •  

    Posting Permissions

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