Jump to content

I heard there were some freaks around here... form thingy


mendoz

Recommended Posts

Hey Freaks.

Well, the situation is like this:
I have a form with an option box, which has "yes" and "no".

I'd thought it'd be cool if when "yes" is selected another table row (tr) would appear and disappear when "no" is selected.

Being a JS noob I need your help.

Thanks,
Dror
Link to comment
Share on other sites

The example below has radio buttons to show/hide row 1 of the table.  The onClick event for each radio button sends the value of the radio button to the Javascript function, which uses that number to determine which row to show/hide.

[code]<form>
  <input type="radio" name="something" value="row1" onClick="showRow(this.value)" /> Yes
  <input type="radio" name="something" value="row1" onClick="hideRow(this.value)" /> No
</form>

<table>
  <tr id="row1" style="display:none;">
    <td>Test 1</td>
    <td>Test 2</td>
  </tr>
  <tr id="row2" style="display:none;">
    <td>Test 3</td>
    <td>Test 4</td>
  </tr>
</table>[/code]


[code]
function showRow(num) {
  document.getElementById(num).style.display = 'block';
}
function hideRow(num) {
  document.getElementById(num).style.display = 'none';
}[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.