dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: onChange Event for Drop Downs

  1. #1
    Join Date
    Mar 2010
    Posts
    3

    onChange Event for Drop Downs

    Hey,
    Please anyone help me out with this. i am quite frustrated with this.
    I have a dropdown with the values populating from database. Now when the user select "New" from the drop down, a new textfield should be seen which is in other case hidden. The code is working absolutely fine with firefox but its not at all working with IE. What could be the problem? What do i have to do extra for making it work. Please help me with this as it is very urgent.

    Code in Head Tag

    <script language ="javascript">
    function abc()
    {
    if(document.form1.select1.value=="New")
    {
    document.form1.textfield3.type = 'text';
    }
    else if(document.form1.select1.value!="New")
    {
    document.form1.textfield3.type = 'hidden';
    }
    }
    </script>

    Code in Body

    <select id="select1" name="select1" onchange="abc()">
    <option value="Select" selected="selected">---Select---</option>
    <option value="New">New</option>
    <?php
    while($row=mysql_fetch_array($res))
    {
    ?>
    <option value="<?php echo $row['category'] ?>"><?php echo $row['category'] ?></option>
    <?php
    }
    ?>
    </select>

    Thanks in advance

  2. #2
    Join Date
    Mar 2010
    Posts
    48
    Try using document.getElementbyId('textfield3').type instead. See if that works.
    Or try to .removeAttribute('type') and right after a .setAttribute('type','hidden').

  3. #3
    Join Date
    Mar 2010
    Posts
    3
    I am grateful for the help but please explain it in a bit detail. I would be very grateful to you.
    Thank You

  4. #4
    Join Date
    Mar 2010
    Posts
    3
    Hey,
    I tried the code:
    function abc()
    {
    if(document.getElementById('select1').value=="New")
    {
    document.getElementById('category').setAttribute('type','text');
    }
    else if(document.getElementById('select1').value!="New")
    {
    document.getElementById('category').setAttribute('type','hidden');
    }
    }

    This code is also working with firefox but not with IE. Can you or anyone please suggest me anything else.
    Thank You

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles