How to reset a radio button using custom Javascript code? RESOLVED

  • AA_C
    Asked on January 26, 2016 at 4:19 PM

    I am trying to reset these radio button fields

    input_76_1006" name="q76_membershipType76[][id]" value="1006" />

    input_76_1007" name="q76_membershipType76[][id]" value="1007" />

    I have this script:

         function fieldReset()     {

            var ind = document.getElementById("input_76_1006").value= '';

            var fam = document.getElementById("input_76_1007").value= '';       

        }

    and this button

    fieldReset()" value="Reset Selection" />

     

    Why won't it work?

     

    How to reset a radio button using custom Javascript code?  RESOLVED Image 1 Screenshot 20

     

     

    The form url below dose not have the script, it is the form where I want to put the script.

     

    Robert

  • Kevin Support Team Lead
    Replied on January 26, 2016 at 7:11 PM

    I checked your Javascript code and it's not working on my end, however, I change your function and used this one: 

    function fieldReset(){

           var ele = document.getElementsByName("q76_membershipType76[][id]");

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

         ele[i].checked = false;

       }

    It should reset the selections, I tried it and worked on my end, replace the name highlighted on the Javascript function with the name of your radio buttons, highlighted on the HTML code below.

    Here is the HTML code:

    <input class="form-checkbox validate[required]" type="radio" id="input_76_1006" name="q76_membershipType76[][id]" value="1006" />

     

    <input class="form-checkbox validate[required]" type="radio" id="input_76_1007" name="q76_membershipType76[][id]" value="1007" />

     

    <input type="button" onDISABLEDclick="fieldReset()" value="Reset Selection" />

    Test it and let us know how it works.

  • AA_C
    Replied on January 26, 2016 at 9:04 PM

    Thank you works perfectly...

    Robert

  • AA_C
    Replied on January 26, 2016 at 10:00 PM

    I just noticed although the radio button is reset the total remains until another selection is made. How can we reset the total to 0 at the same time?

  • Ashwin JotForm Support
    Replied on January 27, 2016 at 3:21 AM

    Hello AA_C,

    Please use the following function and see if that solves your problem:

    function fieldReset(){

           var ele = document.getElementsByName("q76_membershipType76[][id]");

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

         ele[i].checked = false;

         document.getElementById('payment_total').innerHTML='0.00';

       }

    Do test it and get back to us if you have any trouble. You may also like to share the webpage URL where you have implemented the above script as it will help us test the issue.

    Thank you!

  • AA_C
    Replied on January 27, 2016 at 9:37 AM

    YOU GUYS ARE GREAT... I Will have to hone up my JS skills.

    I tried this and it didn't work;

    document.getElementById('payment_total').value= ''0";

    If I may pick your brains, why didn't mine work and

    what is the function of .innerHTML 

     

    Thanks Very Much, Problem Solved

    Robert

  • Ashwin JotForm Support
    Replied on January 27, 2016 at 11:49 AM

    Hello Robert,

    ".innerHTML" is used to set the value of span, div or <td> etc elements other than the form input elements. 

    Since the "payment_tool" is actually span in the form, that is the reason why it did not work for you. I am glad to know that your issue is now resolved. 

    Do get back to us if you have any questions.

    Thank you!