I've got a simple form set up with two buttons (Buying & Renting), when clicked they call their javascript and show their respective prices (Buying Price, Renting Price) which are obviously different.
The problem is that when I reload the page and the Rental radio button is checked, it doesn't show the "Renting Prices", and I'm having to re-click the Renting button for it to call the javascript and display the correct pricing.
Is there such thing as an onCheck event or something similar that would call the javascript when the radio button is checked rather than clicked?
You'll have to wait for the DOM ready, then check the value of each radio button and figure out which is checked, and fire off the proper JavaScript to make it happen. This isn't going to happen with inline JavaScript as you have there, but it's doable and the correct way to handle it.
Sorry to be a bother Chris, but is there a way to add a value to that IF statement? At the moment whenever either one of the RentalPeriod radio buttons are checked it's calling the 'buy' JavaScript every time.
That's fine for the Buying button, but I need it to call the 'rent' script when the Rental radio button is checked.
Hope that made sense, and thanks for all the help - you're a star!
I've got a simple form set up with two buttons (Buying & Renting), when clicked they call their javascript and show their respective prices (Buying Price, Renting Price) which are obviously different.
The problem is that when I reload the page and the Rental radio button is checked, it doesn't show the "Renting Prices", and I'm having to re-click the Renting button for it to call the javascript and display the correct pricing.
Is there such thing as an onCheck event or something similar that would call the javascript when the radio button is checked rather than clicked?
Here's what I'm working with:
<input name="RentalPeriod" type="radio" value="0" onClick="javascript:configureprices('buy');"
checked="checked"/><span class="type-radio">Buying</span>
<input name="RentalPeriod" type="radio" value="3" onClick="javascript:configureprices('rent');"
<?php if($_GET['RentalPeriod'] == "3") { echo("checked"); } ?> />
<span class="type-radio">Renting</span>
Thanks in advance!
IF the checked rental period has a value of 0, display the 'buy' prices. ELSE display the 'rent' prices.
Sorry, I'm extremely unfamiliar with jQuery.
Normally I use the braces even for just an IF statement anyway, but if you are just doing one line as I was above, you can skip them.
That's fine for the Buying button, but I need it to call the 'rent' script when the Rental radio button is checked.
Hope that made sense, and thanks for all the help - you're a star!
$(function() {
if ($("input[name=RentalPeriod]:checked").val() == '3') {
configureprices('rent');
} else {
// whatever
}
});
Thanks a bunch Chris!