Well, my question is the following would it be possible for me to have a radio input with for example the values:
Portugal Spain France Brazil, Germany
And the person can select 2 options or later when it is passed to PHP had 2 values?
Thank you
Well, my question is the following would it be possible for me to have a radio input with for example the values:
Portugal Spain France Brazil, Germany
And the person can select 2 options or later when it is passed to PHP had 2 values?
Thank you
You can achieve the desired using the element input type='checkbox'
JS code taken from here: link
function teste() {
var choices = [];
var els = document.getElementsByName('check');
for (var i = 0; i < els.length; i++) {
if (els[i].checked) {
choices.push(els[i].value);
}
}
alert(choices);
}
<input type="checkbox" value="Brasil" name="check">Brasil
<br/>
<input type="checkbox" value="Portugal" name="check">Portugal
<br/>
<input type="checkbox" value="Espanha" name="check">Espanha
<br/>
<input type="checkbox" value="França" name="check">França
<br/>
<input type="checkbox" value="Alemanha" name="check">Alemanha
<br/>
<input type="button" value="checar" onclick="teste()">
Explaining line by line what the code does:
WiththisrequirementofMINIMUM2SELECTEDFIELDSANDMAXIMUM2SELECTEDFIELDSyoucan:
function teste() {
var choices = [];
var els = document.getElementsByName('check');
for (var i = 0; i < els.length; i++) {
if (els[i].checked) {
choices.push(els[i].value);
}
}
if (choices.length <= 1 || choices.length > 2) {
alert('necessario 2 campos selecionados');
}else{
alert('ok, window.submit();');
}
alert(choices);
}
<input type="checkbox" value="Brasil" name="check">Brasil
<br/>
<input type="checkbox" value="Portugal" name="check">Portugal
<br/>
<input type="checkbox" value="Espanha" name="check">Espanha
<br/>
<input type="checkbox" value="França" name="check">França
<br/>
<input type="checkbox" value="Alemanha" name="check">Alemanha
<br/>
<input type="button" value="checar" onclick="teste()">