Forms 365: JavaScript to Set Option Buttons only works once

  • 25 May 2018
  • 1 reply
  • 14 views

Badge +5

I am trying to set the value of a choice control, rendered as option (radio) buttons using JavaScript...the JavaScript is called by clicking a button (client click).

Example function is below. This function works properly once, and once only per form load. After initially successfully setting the option button, any subsequent click of the button does not set it back to "Stage 2 - Proposal and Corrective Actions". However the 2 alerts on either side of that line do pop up.

So the function is successfully called each time the button is clicked, the actual value setting only works on the first click. Why?

function Stage2() { 
alert("Starting Stage 2 function");
NWF$('#' + varStage).find('input:radio[value="Stage 2 - Proposal and Corrective Actions"]').attr("checked","true").change();
alert("Ending Stage 2 function");
return false;
}

Breaking down the function:

varStage - is the JavaScript variable for the choice control

.change() is used as otherwise rules based on this value being set do not fire

I have also tried the below line but the behaviour is identical:

NWF$('#' + varStage).find('input:radio[value="Stage 2 - Proposal and Corrective Actions"]').attr("checked","checked").change();


1 reply

Badge +5

OK, so all I had to do was change attr to prop!

NWF$('#' + varStage).find('input:radio[value="Stage 2 - Proposal and Corrective Actions"]').prop("checked","true").change();

Reply