Problem accessing OnChange javascript event of Radio Button
I'm running in to the same problem this individual has. Specifically, I'm trying to get a clientside onchange
javascript event to fire for my Radio Button. Unfortunately, the code gets rendered with the onchange
located on a span surrounding the radio button instead of on the radio button itself.
I am using other javascript within the page to manipulate the radio buttons, so onclick
doesn't fully sa开发者_开发技巧tisfy my needs.
Additionally, the answer that was given to the user in the link above was "too bad, use an html check box". For my application, this is sub-par as I need the radio button to raise the OnCheckedChange event serverside.
One solution path I was attempting to go down (using jQuery 1.1.3.1) was to set the change events myself:
jQuery("input:radio").change(new function() {
setParent(jQuery(this));
showUndo(jQuery(this));
});
Which mirrors the onclick
event (which is currently implemented and I'm trying to convert to the onchange ;) )
onclick="setParent(this); showUndo(this);"
This didn't work, though. :'(
The following works for me as expected. The event fires if the radio is changed, and 'this' in the onchange event handler points to the radio button object.
<div id="test">
<input type="radio" name="something"/>
<input type="radio" name="something"/>
</div>
<script type="text/javascript">
$(document).ready(function() {
$(":radio").change(function() {
alert(this.name + ' changed');
});
});
</script>
Does this solve your problem?
精彩评论