Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

radio button on ui page

Rj27
Mega Guru

Hi,
I have 2 radio buttons on my ui page with options yes/no.
I want to make this mandatory and allow only one value to be selected at time.
Currently, both options are getting selected.
My code :

<label>select your option </label><br/>
<input type="radio" name="yes" id="yes" value="Yes">Yes</input><br/>
<input type="radio" name="no" id="no" value="No">No</input><br/>

 

find_real_file.png

1 ACCEPTED SOLUTION

@Rj27 

for mandatory add required="true" to one of the tag

<label>select your option </label><br/>
<input type="radio" name="my_button" id="yes" value="Yes" required="true">Yes</input><br/>
<input type="radio" name="my_button" id="no" value="No">No</input><br/>

OR

try this

<label>select your option </label><br/>
<input type="radio" name="my_button" id="yes" value="Yes" required>Yes</input><br/>
<input type="radio" name="my_button" id="no" value="No">No</input><br/>

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

since you have given different value for your name attribute it's allowing you to select both

Ensure you keep the name attribute same

<label>select your option </label><br/>
<input type="radio" name="my_button" id="yes" value="Yes">Yes</input><br/>
<input type="radio" name="my_button" id="no" value="No">No</input><br/>

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Rj27 

for mandatory add required="true" to one of the tag

<label>select your option </label><br/>
<input type="radio" name="my_button" id="yes" value="Yes" required="true">Yes</input><br/>
<input type="radio" name="my_button" id="no" value="No">No</input><br/>

OR

try this

<label>select your option </label><br/>
<input type="radio" name="my_button" id="yes" value="Yes" required>Yes</input><br/>
<input type="radio" name="my_button" id="no" value="No">No</input><br/>

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader