• Resolved 2ndbeeston

    (@2ndbeeston)


    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]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author EDGARROJAS

    (@edgarrojas)

    Sorry i don’t have the code that would do what you want, probably it would be easier to assign a value of each checked box and then just sum them using formulashttps://sfmanual.rednao.com/documentation/calculatedfields/creating-formulas/

    Also regarding the clear button, you can add a ‘submit button’, although it is called submit button in its settings it can also be configured to clear the form without submitting it.

    Regards!

    Thread Starter 2ndbeeston

    (@2ndbeeston)

    Have tried this as a first stab at the formula for the Stripe value.
    Can’t figure out why it returns the error “SyntaxError: identifier starts immediately after numeric literal” on validation

    TotalValue = 0;
    if($$field_race1$$.value >= 0){TotalValue = TotalValue+1;}
    if($$field_race2$$.value >= 0){TotalValue = TotalValue+1;}
    if($$field_race3$$.value >= 0){TotalValue = TotalValue+1;}
    if($$field_race4$$.value >= 0){TotalValue = TotalValue+1;}
    if($$field_race5$$.value >= 0){TotalValue = TotalValue+1;}
    if($$field_race6$$.value >= 0){TotalValue = TotalValue+1;}
    if($$field_race7$$.value >= 0){TotalValue = TotalValue+1;}
    if($$field_race8$$.value >= 0){TotalValue = TotalValue+1;}
    if (TotalValue > 0){return TotalValue;}

    • This reply was modified 3 years, 2 months ago by 2ndbeeston.
    Thread Starter 2ndbeeston

    (@2ndbeeston)

    Hi
    Taking a different tack after looking at soem other forum responses:
    https://www.ads-software.com/support/topic/get-checkbox-value/

    Now trying checkboxes, but still get a validation error on first line
    “SyntaxError: identifier starts immediately after numeric literal”

    if($$field_RaceCheck1$$.Ischecked(‘horse 1’)(TotalValue = 1}
    else(TotalValue = 0}
    if($$field_RaceCheck1$$.Ischecked(‘horse 2’)(TotalValue = TotalValue+1}
    if($$field_RaceCheck1$$.Ischecked(‘horse 3’)(TotalValue = TotalValue+1}
    if($$field_RaceCheck1$$.Ischecked(‘horse 4’)(TotalValue = TotalValue+1}
    if($$field_RaceCheck1$$.Ischecked(‘horse 5’)(TotalValue = TotalValue+1}
    $$field_TotalValue$$.value = TotalValue

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘how to include ‘onchange’ to trigger a javascript function’ is closed to new replies.