JavaScript radio button confirmation

后端 未结 2 1568
别跟我提以往
别跟我提以往 2020-12-11 12:34

I am trying to add a function, or additional JavaScript to the existing function for a confirmation. I will need a confirmation box once the submit button is clicked saying,

2条回答
  •  轮回少年
    2020-12-11 12:50

    Set your radio buttons' values like this:

     : GCSE
    : A2
    : AS

    Then use this script in your function to validate form or make it a function and call it from your function validateForm:

    var checked = null;
    var inputs = document.getElementsByName('examtype');
    for (var i = 0; i < inputs.length; i++) {
              if (inputs[i].checked) {
               checked = inputs[i];
               break;
       }
    }
    if(checked==null)
    {
        alert('Please choose an option');
        return false;
    }
    else{
        return confirm('You have chosen '+checked.value+' is this correct?');
    }
    

提交回复
热议问题