how to include ‘onchange’ to trigger a javascript function
-
Hi
I am trying to create a form where users can use radio buttons to select which items (horses) they wish to buy for a charrity race night event.I have incorporated some javascript that counts how many buttons on the page have been checked to put the total into a readonly field that will be used for charging and Stripe payment.
What I need to do is have an onchange field to call the function for each radio button set.
ALSO, is there a resset/clear button in the form builder? I can’t find one.The javascript that is being called is:
function CalcHorseTotal(){
var HorseTotal;
var HorsePrice;
HorseTotal = 0;
HorsePrice = 5;var race1= document.getElementsByName(‘race1’);
for(var i = 0; i < race1.length; i++){
if(race1[i].checked){
HorseTotal = HorseTotal+1;
}
}
var race2= document.getElementsByName(‘race2’);
for(var i = 0; i < race2.length; i++){
if(race2[i].checked){
HorseTotal = HorseTotal+1;
}
}
var race3= document.getElementsByName(‘race3’);
for(var i = 0; i < race3.length; i++){
if(race3[i].checked){
HorseTotal = HorseTotal+1;
}
}
var race4= document.getElementsByName(‘race4’);
for(var i = 0; i < race4.length; i++){
if(race4[i].checked){
HorseTotal = HorseTotal+1;
}
}
var race5= document.getElementsByName(‘race5’);
for(var i = 0; i < race5.length; i++){
if(race5[i].checked){
HorseTotal = HorseTotal+1;
}
}
totalhorses.value = HorseTotal;
alert(“TEST HorseTotal = ” + HorseTotal );
//Here you can put code that you want to be executed before the form is submitted
}
}`The page I need help with: [log in to see the link]
- The topic ‘how to include ‘onchange’ to trigger a javascript function’ is closed to new replies.