mapping radio buttons to true/false fields

yundlu316
Kilo Guru

I have a UI Page that has a radio button with the following three options:

<input type="radio" name="status" id="single" style="text-align:left"> Single</input>

<input type="radio" name="status" id="married"> Married</input>

<input type="radio" name="status" id="married_but"> Married, but withhold at higher Single rate.</input>

I'm trying to pull the value of whatever the user chooses and insert it into a table where Single, Married, and Married but withhold at higher Single rate are all individual True/False fields.   So ideally, if someone selects Single in the UI Page, the script would mark Single with an "x" indicating that it is true.   I've tried the below code, which works great with text fields, but was wondering how to do it for radio buttons that map back to true/false fields.

function submitRequest()

{

var gr = new GlideRecord('u_table');

gr.initialize();

  gr.variable_a= document.getElementById('A').value;

  gr.variable_b= document.getElementById('B).value;

  gr.variable_c= document.getElementById('C').value;

gr.insert();

}

1 ACCEPTED SOLUTION

tanumoy
Tera Guru

Make the default value False for all the True/False field in the form, then try the below script.




function submitRequest()


{


var gr = new GlideRecord('u_table');


gr.initialize();


if (document.getElementById('single').checked) {
  gr.variable_a
= True;
}


if (document.getElementById('married').checked) {
  gr.variable_a
= True;
}


if (document.getElementById('married_but').checked) {
  gr.variable_a
= True;
}


gr.insert();


}


View solution in original post

3 REPLIES 3

tanumoy
Tera Guru

Make the default value False for all the True/False field in the form, then try the below script.




function submitRequest()


{


var gr = new GlideRecord('u_table');


gr.initialize();


if (document.getElementById('single').checked) {
  gr.variable_a
= True;
}


if (document.getElementById('married').checked) {
  gr.variable_a
= True;
}


if (document.getElementById('married_but').checked) {
  gr.variable_a
= True;
}


gr.insert();


}


Amazing, thanks Tanumoy!   This code didn't work at first, but I simply deleted the quotes around "True" and it worked fantastically.   Thanks again!


Oops... that was a mistake. Thanks for correcting that... I have edited that... Thanks again.