The following is the javascript code that I was trying to use:
<script type="text/javascript">
$(function(){
// When the Event amount is checked
$(".eventAmount").click(function(){
$("#event-price").val(this.value); // Put the value into the Amount field
});
});
</script>
The problem is that the above code is not inserting the value of the radio button that’s selected. I wondered if someone could help me with the code?
I removed the display none which revealed the input however it didn’t populate with the value from the selected radio button.
I tested it out at the following url:
… but it didn’t work.
My js skills are quite basic but as the code seems to be a function, am I supposed to call the function in order to get it to work or could you help me revise the code so that it will just run without calling the function?
Thanks so much for that tip. I tested and it’s populated correctly now. I still need the input field to be hidden though so I’m wondering if I can’t use display: none is there some other method to hide the field?
Ok thanks, I’ll try input=“hidden”. The reason why I need to insert the amount in the hidden input field is that it’s needed in another part of the script where the amount populates a variable as follows:
var price = $(‘#event-price’).text();
The rest of the code can be seen below.
I mentioned in an earlier post that the original code that I posted ended up working in jsfiddle but for some reason it’s not working amid the other surrounding code when placed on the full webpage so I’m wondering whether there’s some conflict between other javascript on the page.
Would you know why it wouldn’t be working on the web page or would you need to see the full code? If yes, could I PM you? I know that private messaging isn’t usually preferred but I would just need to make the page live temporarily so you could look at it and then disable it again as it’s not working.
<script>
var guests = 0;
function calc() {
var numberOfGuests = 0;
$(".guestrow").each(function() {
numberOfGuests+= $(this).find(".cat_textbox").val()!="";
});
var price = $('#event-price').text();
var participants = numberOfGuests+1;// add the organiser
var total = participants*price;
$("#BookingAllocation").val(participants);
$("#booked").toggle(numberOfGuests>0); // only show booked if guests
$("#Amount").val(total.toFixed(2));
}
$(function () {
calc();
$(".cat_textbox").on("keyup",function() { calc(); /* handle removal of gues*/});
$("#catwebformbutton").on("click", function () {
guests++;
if (guests <= 10) {
$(".guestrow").eq(guests-1).show();
}
$("#removeGuest").toggle(guests>0);
calc();
});
$("#removeGuest").on("click",function(e) {
guests--;
$(this).toggle(guests>0);
var $row = $(".guestrow").eq(guests);
$row.find(".cat_textbox").val("");
$row.hide();
calc();
});
$('form[name="catwebformform81201"]').on("submit", function (e) {
calc();
if (checkWholeForm81201(this)) {
// ...
}
else {
e.preventDefault(); // cancel submit
}
});
});
</script>