I'm new to jQuery and trying to figure this out.
I have a web page filled with several sets of radio buttons based on several computer components. I have some images at the top of my page that trigger certain radio buttons to be pushed. The JavaScript I have for this is:
$( document ).ready( function() {
$('img#gaming').click(function () {
$('.small_image').attr("src","../img/GamingPlain.png");
$('input:radio[name=chasis]')[2].checked = true;
$('input:radio[name=cpu]')[1].checked = true;
$('input:radio[name=mobo]')[1].checked = true;
$('input:radio[name=ram]')[1].checked = true;
$('input:radio[name=gpu]')[1].checked = true;
$('input:radio[name=psu]')[1].checked = true;
$('input:radio[name=hdd]')[2].checked = true;
});
.
.
.
});
This works correctly. I also have to change a portion of the page based on which radio button is selected. It looks like this:
$( document ).ready( function() {
$('input[name=chasis]').change(function() {
var txt = $(this).parent().text();
var price = txt.match(/(\$)([\d]+)/)
$('span#chasisprice').text(price[0]);
});
$('input[name=cpu]').change(function() {
var txt = $(this).parent().text();
var price = txt.match(/(\$)([0-9]+)/)
$('span#cpuprice').text(price[0]);
});
.
.
.
});
This also works correctly. However, when I use the first piece of code (a user click on img#gaming
) to select the automatically select the individual radio buttons, the second piece of code does not trigger (aka a change is not registered).
Is there a different form of .change
that will register the new selected radio buttons, or a different way of selecting the radio button that would register the change?