What is JotForm?
JotForm is a free online form builder which helps you create online forms without writing a single line of code. No sign-up required.

At JotForm, we want to make sure that you’re getting the online form builder help that you need. Our friendly customer support team is available 24/7.

We believe that if one user has a question, there could be more users who may have the same question. This is why many of our support forum threads are public and available to be searched and viewed. If you’d like help immediately, feel free to search for a similar question, or submit your question or concern.


  • Profile Image

    Javascript if/else with onClick event ?

    Asked by biiainsurance on February 18, 2014 at 10:41 PM

     

    Not sure if my initial question made sense :o)

     

    @Elton wrote me a script for calculating rates but now I need to make two sets of rates based on a radio button trigger earlier in the form.

     

    The variable I am trying to use to check for value is set 

     

    var unitPurpose = document.getElementById('q67_unitPurpose'); 

     

    Then I check if that value is Remodeler to show one set of rates and if not show another set. The rates are set in a function so maybe the if /else needs to be outside of the function ?

     

    Form: 40187615170148 

     

    function getRate(){

    if (unitPurpose.value == 'Remodeler'){

    //first

    if (propert[0].checked == true && firstprocoast[0].checked == true) ratevalue.value = 0.55;

    if (propert[0].checked == true && firstprocoast[1].checked == true) ratevalue.value = 0.55;

    if (propert[0].checked == true && firstprocoast[2].checked == true) ratevalue.value = 0.55;

    } else {

    if (propert[0].checked == true && firstprocoast[0].checked == true) ratevalue.value = 0.14;

    if (propert[0].checked == true && firstprocoast[1].checked == true) ratevalue.value = 0.24;

    if (propert[0].checked == true && firstprocoast[2].checked == true) ratevalue.value = 0.12;

    }

    };

    #### would it work like above or would it work like below ? Either way I am still missing something but not sure where, was thinking an onClick event maybe ? 

     

    if (unitPurpose.value == 'Remodeler'){

    function getRate(){

    //first

    if (propert[0].checked == true && firstprocoast[0].checked == true) ratevalue.value = 0.55;

    if (propert[0].checked == true && firstprocoast[1].checked == true) ratevalue.value = 0.55;

    if (propert[0].checked == true && firstprocoast[2].checked == true) ratevalue.value = 0.55;

    };

    } else {

    function getRate(){

    if (propert[0].checked == true && firstprocoast[0].checked == true) ratevalue.value = 0.14;

    if (propert[0].checked == true && firstprocoast[1].checked == true) ratevalue.value = 0.24;

    if (propert[0].checked == true && firstprocoast[2].checked == true) ratevalue.value = 0.12;

    };

    };

    Page URL:
    http://biiainsurance.com/builders-risk-form/Risk-Coverage.html

    checked 3 document and
  • Profile Image

    Answered by biiainsurance on February 19, 2014 at 08:23 AM

    I even tried to if/else the click array

    unitPurpose.onclick = unitPurpose.onchange = function(){

    if (unitPurpose.value = 'Remodeler')

    {

    //click events

    for (var i = 0; i<firstprocoast.length; i++) {

      firstprocoast[i].onclick = 

      secondprocoast[i].onclick = 

      thirdprocoast[i].onclick = 

      fourthprocoast[i].onclick = getRateRemod;

    };

    } else {

    //click events

    for (var i = 0; i<firstprocoast.length; i++) {

      firstprocoast[i].onclick = 

      secondprocoast[i].onclick = 

      thirdprocoast[i].onclick = 

      fourthprocoast[i].onclick = getRate;

    };

    }

    }