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

    Access radio button value using javascript

    Asked by biiainsurance on February 24, 2014 at 10:54 AM

    Hello,

    I am trying to access the value of a radio button in the form to do a comparison. After googling and testing different examples I am still unsuccessful in doing so. I now understand that it is done with a for() vs an if/else since I have to run through each button to check for value but I am having no luck in checking value then doing an if/else inside to present a different function. Any advice would be much appreciated. 

    check different hello then
  • Profile Image
    JotForm Support

    Answered by TitusN on February 24, 2014 at 12:43 PM

    Hello,

    Thank you for contacting us.

    Just to clarify:

    You want to trigger another JS script (perhaps and if/else function) with the value of the radio button, right?

    Please share the script you are currently working on - and perhaps what you want to achieve, we will take a look and advice. 

    Its worth noting that the radio button value will only be accessed if you downloaded the full source code of the form and placed it on your site.

    Please let us know.

  • Profile Image

    Answered by biiainsurance on February 24, 2014 at 12:57 PM

    Hello,

    Yes Elton has helped me with some scripts recently but I now need to take them a step further. They are sitting on my server and I am at a total loss. I have tried for statements combined with if/else and nesting functions but if one thing fixes another breaks or the functionality totally breaks.

    What the script elton wrote originally did was provide seperate values for different sets of radio buttons based on option selected.

    for (var i = 0; i<firstprocoast.length; i++) {
    firstprocoast[i].onclick =
    secondprocoast[i].onclick =
    thirdprocoast[i].onclick =
    fourthprocoast[i].onclick = getRate;

    };

    with the function getRate containing the set values for different radio button options. However I now need to have two sets of rates based on a different selection so up to my most recent attempt I have assigned an onclick to the 4 radio button options to trigger this function

    //check is remodeler

    function is_remodeler(upurpval){
    if (upurpval == "Remodeler") {
    alert("worked");
    //click events
    for (var i = 0; i<firstprocoast.length; i++) {
     firstprocoast[i].onclick = 
     secondprocoast[i].onclick = 
     thirdprocoast[i].onclick = 
     fourthprocoast[i].onclick = getRateRemod;
    };

    } else {

       alert("did not work");
                for (var i = 0; i<firstprocoast.length; i++) {
      firstprocoast[i].onclick = 
      secondprocoast[i].onclick = 
      thirdprocoast[i].onclick = 
      fourthprocoast[i].onclick = getRate; 

    }

     

    The working form is here from Eltons original scripts plus a few modifications I made on my own and my new "test form" is here.

    So to sum up what I am now attempting from looking at the form:

    If they choose "unit purpose" - "remodeler" they get the 1 set of rates from "getrate" or as I have added "getrateremod" and if they choose anything else other than "unit purpose" - "remodeler" they get the original function "getrate".  

    I hope that makes sense. I have been googling and trying different examples since last week and still have not come up with a working script but that could just be my inexperience.

    Thank you for your help! 

  • Profile Image

    Answered by biiainsurance on February 24, 2014 at 12:59 PM

    I was also doing some testing at this url if it helps any ?? http://jsfiddle.net/zZ68r/

  • Profile Image
    JotForm Support

    Answered by TitusN on February 24, 2014 at 01:56 PM

    Hello,

    Thank you for the response.

    Yes, the information is definately helpful.

    I have looped in Elton so that we can consider the soluton.

    Thank you for your patience.

     

  • Profile Image

    Answered by biiainsurance on February 24, 2014 at 03:01 PM

    Thank you so much!! I appreciate the lengths you all go to help out. 

  • Profile Image

    Answered by biiainsurance on February 25, 2014 at 06:18 PM

    Just wanted to touch base and see if you guys had any thoughs so far?

  • Profile Image

    Answered by EliezerN on February 25, 2014 at 08:39 PM

    @biiainsurance

    Your message has been forwarded to my colleague so that he can get back to you with the update on this once he is available.

    Your patience is highly appreciated.

    Thanks

  • Profile Image
    JotForm Support

    Answered by EltonCris on February 26, 2014 at 11:55 PM

    @ biiainsurance

    Sorry for getting back to you this late. I have checked your sample form and it seems working according to your requirements.

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

    Did you managed to figured out everything already?

    Please let us know should you have more questions.

    Best Regards!

  • Profile Image

    Answered by biiainsurance on February 27, 2014 at 08:05 AM

    @Elton

    I was playing around with it more yesterday and got it to where it is now. I was unsure if it was correctly coded. It is essentially doing what I wanted it to do however I did notice after some testing that if I were to click on say "remodeler" then "unit type" then "Is Property Coastal" and choose option to get the rate, if I were to go back and change it from "remodeler" to any of the other options then the rate does not automatically update to reflect the new selection. That might be a little picky and the user should not go back and rechoose the option so I am not really worried at the moment with that.  

    I do appreciate your respones and no worries on taking a couple of days to get back :o) I was not meaning to be impatient. I greatly appreciate all that you guys have done to help out !!  

  • Profile Image

    Answered by EliezerN on February 27, 2014 at 11:06 AM

    Thanks for the update on this matter.

    Please let us know in case you need further assistance with this inquiry.

    Thanks