Jump to content

Checking if radio buttons have been selected without submitting form


PerpsTherapy

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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.