I’m trying to get that when you click on a row in the table then the radio button on the same row will be selected.
Have anyone some suggestions for how this can be done?
<form name="form1" method="post" action="">
<table id="simplehighlight" class="REW_table" style="width: 350px; margin-left: auto; margin-right: auto;" >
<thead></thead>
<tr><td><input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_0"></tr>
<tr><td><input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_0"></tr>
<tr><td><input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_0"></tr>
<tr><td><input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_0"></tr>
<tr><td><input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_0"></tr>
</table>
</form>
Javascript:
$(document).ready(function(){
$('#simplehighlight tr').hover(function(){
$(this).children().addClass('datahighlight'); // Mark lightgray
$(this).click(function(){
$('#simplehighlight tr').children().removeClass('datahighlight_select'); // Remove all old blue mark
$(this).children().addClass('datahighlight_select'); // Mark blue
});
},function(){
$(this).children().removeClass('datahighlight'); // Remove lightgray
});
});
Try:
Using
.prop()with.find()and binds to the click event using.click()Also note that your HTML as posted is invalid:
inputtags should be self-closing and,</td>tag.idattribute, which is not allowed.Here’s an example: http://jsfiddle.net/yJ3RN/ (also corrects the HTML problems)