Jump to content

Checking if radio buttons have been selected without submitting form


Recommended Posts

Greetings to all.

Is there anyway to assertain whether a radio button has been selected without submitting the form it is a part of? I have two radio buttons that I want to act as a switch for displaying an additional text area element of the form when one of the radio buttons is selected, but not the other. Is it possible to determine whether a radio button has been selected without submitting the form?

Many thanks,

- PerpsTherapy
[quote author=artacus link=topic=118568.msg484598#msg484598 date=1166077861]
I guess I'll wait and see if he finds his post before I answer.
[/quote]

Hehe, found my post. I wasn't aware it couldn't be done with php. How would one go about doing something like this with javascript??

Many thanks,

- Perpstherapy
PHP is a server side technology so you can control if a radio button is selected when it is sent off to the user's browser. But you need to check if a button is selected after the user has fooled around with it, so you need javascript.
<input type="radio" name="myRadioBtn" value="1" />
[code]
function checkform() {
  for(var i=0; i<form1.myRadioBtn.length; i++) {
      if(form1.myRadioBtn[i].checked) {
        alert(form1.myRadioBtn[i].value);
        ...do something
      }
  }
}[/code]
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.