www.webdeveloper.com
Results 1 to 4 of 4

Thread: Change radio button check value onClick

Hybrid View

  1. #1
    Join Date
    Feb 2004
    Posts
    29

    Question Change radio button check value onClick

    I have a 4 rows each row is has a label and a radio button.
    I want to make it possible to click on the row to make the radio button on the clicked row true.

    Here is an example of my markup
    HTML Code:
    <form name="quiz" id="quizable">
    <table id="q_table">
    <tr><td>Banana</td><td><input type="radio" name="q1" id="q1_1" /></td></tr>
    <tr><td>Apple</td><td><input type="radio" name="q1" id="q1_2" /></td></tr>
    <tr><td>Coconut</td><td><input type="radio" name="q1" id="q1_3" /></td></tr>
    <tr><td>Cherry</td><td><input type="radio" name="q1" id="q1_4" /></td></tr>
    </table>
    </form>

  2. #2
    Join Date
    Jun 2009
    Posts
    36
    Try something like this

    Code:
    <tr onclick="document.getElementById('q1_1').checked=true;">

  3. #3
    Join Date
    Oct 2008
    Location
    U.S.
    Posts
    726
    You don't need javascript for this, this is what the <label for="idOfInputHere">label text</label> tags are for: http://www.w3schools.com/tags/tag_label.asp

  4. #4
    Join Date
    Feb 2004
    Posts
    29
    I know that <label for="name">Question</label> will do it but you cannot add a for to a <tr> for only is used on labels. Thanks to Trassic. I modified your script a bit and works perfect. Thanks!

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