How to get value from Radio type and make it a condition to calculate value in javascript?


Hi all, 

I’m having a form in which I ask if the respondent is a Client or not, then calculate his/her payment for the number of ticket he/she wants to purchase.

If the customer is Client, then he/she gets one ticket for free; otherwise, normal number of ticket multiplies by unit price.

I have a set up like this: 

All of the questions were put in one Custom group.

Here’s the Javascript: 

function ClientPayment(ticket) {
    var payment = (ticket-1)*100000;
    return payment;

function NonClientPayment(ticket) {
    var payment = ticket*100000;
    return payment;

$(document).ready(function() {

    $(‘.ticket input[type=text]’).attr(‘placeholder’, ‘Ticket’);
    $(‘.txtPayment input[type=text]’).hide();

    $(‘.calculate’).click(function() {
        var ticket = $(‘.ticket input[type=text]’).val();
        var client = $(‘.client input[type=radio]:checked’).val();

        if (client == “Yes”){
            var txtPayment = ClientPayment(ticket);
        } else{
            var txtPayment = NonClientPayment(ticket);

    $(‘.txtPayment input[type=text]’).val(txtPayment);
    $(‘.total-payment’).text(‘Your payment is ‘ + txtPayment);

When I test run it, it doesn’t work with “Yes” being checked. Kindly see it here:

So can anyone please help me.

Another problem is that the button is not shown once run in test.

I’m having “Standard” package for SurveyGizmo and using Chrome version 56.

Thank you very much in advance for all your advice.

Thi An.

freigabe answered

    Hi all,

    Along the line of the above question, is there any way for us to NOT press the “Calculate” button but only need the user to type in the box Ticket and the result will be shown.

    The process will somehow like this:

    User Choose “Yes”-> type number of Ticket -> The result appears.

    User choose “No” -> The result changed (real time)

    User change number of ticket -> the result changed (real time)

    Thank you very much for all your help.


    freigabe answered
      IS 2.21K Rep.

      One way to find option values without the Survey Legend is to look at the html code for the survey page. There may be better ways that I can’t think of right now.

      For example, if you are familiar with any tools like Chrome’s Developer Tools (Menu -> More Tools -> Developer Tools) or similar options in Firefox or IE/Edge, you can inspect the html code for the option in preview or a live survey. The code for the response option will be something like:

      <input type=”radio” …more stuff here… value=”10112″ …more stuff… >

      The option ID is equal to the value.

      I am not sure what the issue is with your calculate button. I only dabble in JavaScript and I couldn’t find a simple answer.


      IS answered
        IS 2.21K Rep.

        The Value of the checked radio button will not ever be “Yes”. It will be the option value and will be more like “10112”.

        You can look up the option value using Tools -> Survey Legend

        for more info, see:

        tpthiangmailcom commented
          • Thanks for your help! It works! However, I can’t use Survey Legend as my package is only Standard. How will I get the Option ID if I can’t access to Survey Legend?

            Another point I mentioned in my question is the display of “Calculate” button. Would you be able to help me out with that?



          Question stats

          • Active
          • Views8763 times
          • Answers3 answers
          • Followers2 followers