Phiên bản đầy đủ: jsB@nk » Biểu mẫu » Ô chọn » Tạo các nút radio
URL: https://www.javascriptbank.com/radio-question-validator-script.html
Hiệu ứng tạo các nút radio để người dùng mỗi lần chỉ được phép chọn một.
Phiên bản đầy đủ: jsB@nk » Biểu mẫu » Ô chọn » Tạo các nút radio
URL: https://www.javascriptbank.com/radio-question-validator-script.html
<SCRIPT LANGUAGE="JavaScript">// David Blackledge | http://david.blackledge.com/<!-- Beginfunction checkRadios() { var el = document.forms[0].elements; for(var i = 0 ; i < el.length ; ++i) { if(el[i].type == "radio") { var radiogroup = el[el[i].name]; // get the whole set of radio buttons. var itemchecked = false; for(var j = 0 ; j < radiogroup.length ; ++j) { if(radiogroup[j].checked) { itemchecked = true; break;} } if(!itemchecked) { alert("Please choose an answer for "+el[i].name+"."); if(el[i].focus) el[i].focus();return false; } } } return true;} // End --></script><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->
<FORM onsubmit="return checkRadios(this);">Blue:<input type="radio" value="1" name="blue"><input type="radio" value="2" name="blue"><input type="radio" value="3" name="blue"><input type="radio" value="4" name="blue"><input type="radio" value="5" name="blue"><BR>Red:<input type="radio" value="1" name="red"><input type="radio" value="2" name="red"><input type="radio" value="3" name="red"><input type="radio" value="4" name="red"><input type="radio" value="5" name="red"><BR><input type="submit" value="check" name="button"></FORM><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->