zaniku
zaniku

Reputation: 41

I need some help on validating the below code in javascript

I would like to validate the below code in js so that the user has to check one but i do not know how to. The form name is 'registration'

<li>
   <input type="checkbox" name="en" value="en"  />
   <span>English</span>
</li>
<li>
   <input type="checkbox" name="nonen" value="noen" />
   <span>Non English</span>
</li>   

Upvotes: 4

Views: 96

Answers (4)

Sagar HL
Sagar HL

Reputation: 11

<li>
 <input type="radio" name="nonen" value="en" checked/>
 <span>English</span>
</li>
<li>
 <input type="radio" name="nonen" value="noen"/>
 <span>Non English</span>

<li>
 <input type="radio" name="nonen" value="en" checked/>
 <span>English</span>
</li>
<li>
 <input type="radio" name="nonen" value="noen"/>
 <span>Non English</span>

Upvotes: 1

Umer Farooq
Umer Farooq

Reputation: 19

<li><input type="checkbox" name="en" value="en"  /><span>English</span></li>
<li><input type="checkbox" name="en" value="en" /><span>Non English</span></li>

In check box name must be same if all check boxes are selected. Try thid code.

Upvotes: 1

Augusto Pohl
Augusto Pohl

Reputation: 141

You could try this one

<input type="radio" name="raden" id="english" checked>
<label for="english">English</label>
<input type="radio" name="radnon" id="nonenglish">
<label for="nonenglish">Non-English</label>       

Upvotes: 3

Gabriel Lupu
Gabriel Lupu

Reputation: 1447

Use an input of type radio instead. Here is a link to the MDN documentation, basically all inputs of type radio that have the same name property are grouped together and the user can select only one of them. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/radio

Upvotes: 7

Related Questions