Set radio button as checked based on condition in Service Portal

Talvin Singh
Tera Expert

Hello Reader,

I have two radio button on my widget, Male and Female. When the form loads the gender type is fetched in the server script, either Male or Female. 
How can we set these radio buttons as checked based on the gender type generated at the server script?

Here is my script:

HTML:

<div class="gender">
  <input type="radio" name="inlineRadioOptions" id="inlineRadio1" value="option1">
  <label class="form-check-label male-female-css" for="inlineRadio1">Male</label>
  <input class="form-check-input inputmargin" type="radio" name="inlineRadioOptions" id="inlineRadio2" value   ="option2"/>
  <label class="form-check-label male-female-css" for="inlineRadio2">Female</label>
</div>

Server Script:

data.gender = usr.getDisplayValue('gender');

 

Please let me know.

Thanks

1 ACCEPTED SOLUTION

Mohith Devatte
Tera Sage
Tera Sage

Hello @Talvin Singh ,

Please try this in your client script 

Please replace your values accordingly to your script while comparing c.data.gender with male and female strings
if(c.data.gender=="male")

{

document.getElementById("inlineRadio1").checked = true;
}
else if(c.data.genser=="female")
{
document.getElementById("inlineRadio2").checked = true;
}

Please mark my answer correct if it helps you

View solution in original post

2 REPLIES 2

Mohith Devatte
Tera Sage
Tera Sage

Hello @Talvin Singh ,

Please try this in your client script 

Please replace your values accordingly to your script while comparing c.data.gender with male and female strings
if(c.data.gender=="male")

{

document.getElementById("inlineRadio1").checked = true;
}
else if(c.data.genser=="female")
{
document.getElementById("inlineRadio2").checked = true;
}

Please mark my answer correct if it helps you

RaghavSh
Kilo Patron

You need to make use of client side script in the widget:

if(c.data.gender=='male') 

{

document.getElementById('inlineRadio1').checked=true;

}

else{

document.getElementById('inlineRadio2').checked=true;

}

//compare with the exact string value which is being returned from usr.getDisplayValue('gender');


Raghav
MVP 2023