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

Thread: Onchange event to display a tr

Hybrid View

  1. #1
    Join Date
    Jul 2012
    Posts
    1

    Onchange event to display a tr

    Hello,

    I have a query that is:
    In this table code if selected option is 2 then only div tag should be displayed, else no display.
    <table>
    <tr>
    <td>Select</td>
    <td>
    <select name="selection">
    <option value=1>1</option>
    <option value=2>2</option>
    </select>
    </td>
    </tr>
    <div id="div1">
    <tr>
    <td>Name</td>
    <td><input type="text" size="20"></td>
    </tr>
    </div>
    </table>

  2. #2
    Join Date
    Nov 2007
    Posts
    425
    Improper HTML - so I don't know if any solution would be cross-browser compliant...

    step 1: update your style sheet so that div1 is hidden by default
    e.g.,
    #div1 {display:none;}

    step 2: add an onchange handler to your <select> and give it an ID
    e.g.
    <select name="selection" id="selection" onchange="checkToSeeIfIShouldShowRow1()">

    step 2: write your javascript function for checkToSeeIfIShouldShowRow1
    e.g.
    function checkToSeeIfIShouldShowRow1() {
    var selectedValue = document.getElementById('selection').value
    if (selectedValue == '2'){
    document.getElementById('div1').style.display='inline'
    }
    }

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