Jump to content

Events And Radios


shadowayex
 Share

Recommended Posts

I'm having a little problem. I'm using JavaScript validation on a form and I'm trying to make it slightly automated. Here's what's happening:Let's say you have two radios, and the first one was selected, something like this:

<input type="radio" name="radios1" checked="checked" value="1" /> Option 1<input type="radio" name="radios1" value="2" /> Option 2

Let's say you added a JavaScript event, whether it be onfocus, onblur, onclick, onmousedown, onmouseup, etc. (all the ones I tried followed the behavior that I'm about to explain), you've added one to launch a function to detect which one is checked.My problem is that if the first one is checked, and you check the second one, it still detects the first one is checked. But if you went back to the first one, the second one is detected. It seems teh events are launched before the check effect is activated.Is there any way to reverse this?

Link to comment
Share on other sites

It seems teh events are launched before the check effect is activated.
Correct, because it gives you an opportunity to return false and cancel the event. Pass the radio button to the function so that you can use that to tell which was clicked. e.g.:onclick="func(this);"
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...