Reputation: 13
I am new to jquery and having issues making a function which does the following.
I have table with three rows and four columns each. Inside each column, I have a button with a seperate css for hover effects. The idea of each button is to show their value in a textbox when the button is pressed.
I have tried different ways to do the following but have been unsuccessful.
It is an aspx page so I even tried getting the value by calling the target if of the button. for example:
JS:
//Div Specific Function
$("#step1").click(function (e) {
var thisID = e.target.ty;
$('#input').data('btnType', 'Amount').each(function () {
$(this).toggleClass('button');
})
$(thisID).toggleClass('button-hover');
});
html
<table cellpadding="10" cellspacing="0" width="90%">
<tr>
<td>
<input type="button" data-btnType="Amount" id="btn50" runat="server" value=" $50" Text="$50" class="button" />
</td>
<td>
<input type="button" data-btnType="Amount" id="btn100" runat="server" value="$100" Text="$100" class="button" />
</td>
<td>
<input type="button" data-btnType="Amount" id="btn150" runat="server" Text="$150" value="$150" class="button" />
</td>
<td>
<input type="button" data-btnType="Amount" id="btn200" runat="server" Text="$200" value="$200" class="button" />
</td>
</tr>
</table>
How can I make these buttons act like a radio effect. Please note that there are 10 buttons in all in this div.
Regards.
Upvotes: 1
Views: 1063
Reputation: 1755
$(".button").click(function () {
$(".red").removeClass("red").addClass("yellow"); // remove the prev pressed button class
$(this).removeClass("yellow").addClass("red"); // add the red css class to pressed button
$(".button").not(".red").addClass("yellow"); // add to all other buttons yellow class
$("#textBox").val($(this).val()); // get val of pressed button val
});
Upvotes: 1
Reputation: 5632
You can try this:
$("table :button").click(function() {
$("table :button").removeClass("selected").addClass("unselected");
$(this).removeClass("unselected").addClass("selected");
$("#textBox").val($(this).val());
});
// I have changed your html little, added class unselected in your html code
jsfiddle example:
Upvotes: 0