Calling a JS function on <RADIO> button activities

Hi all,

I seem to be having a problem triggering a JS function whenever there is activity in a set of <RADIO> buttons. As it stands I have to <RADIO> buttons, and once one is selected and the other de-selected (and vice-versa) I would like a function to be called (the function checks to see what <RADIO> button is actually selected).

The HTML is below, and am not sure if I am using the right attribute (onChange() is what I am using).

<tr><td><label for="select_existing_client">Select existing client</label></td><td><input type="radio" id="select_existing_client" name="select_client" onChange="return enable_client_form_elements();" value="current"/></td></tr>
<tr><td><label for="create_new_client">Create new client</label></td><td><input type="radio" id="create_new_client" name="select_client" onChange="return enable_client_form_elements();" value="new" />td></tr>

The problem as it stands is that it only works whenever I select the ‘create_new_client’ <RADIO> button. I know this as my JS function just displays an ALERT message when the function is called, but it is only called when selecting the ‘create_new_client’ <RADIO> field.

Any help is appriciated

Tryst

Hi Tryst,

Personally if there are only two options I’d use a checkbox.

Try this:

onChange="enable_client_form_elements(); return"

If that fails try onClick instead of onChange.

Yeah, i’ve resorted to use the onClick() method. But didn’t want to use checkboxes because I need to only beable to select one from the <RADIO> button set, and I assum that <CHECKBOXES> allow you to select multiple options…

Thanks

Tryst

Semantically it is incorrect to use a radio button for a simple boolean choice.
Though I can think of exceptions.

Just use one checkbox, like “Subscribe to newsletter” or in your case I’d have it prechecked to one option, the most common one, and switch if it’s unchecked / rechecked.

hope it helps