Help me about validate form use javascript!!!
-
-
I had a form like this: Type 1 Type 2 Type 3 Red Green Blue When Submit I want to use javascript check user had check at least one value in radio and checkbox but I dont want to use default "checked" for radio or checkbox. Can u help me, please? Thanks
Include following 2 javascript functions & call CheckSubmit() on form submit. Hope this helps u.:~ function CheckObject(chkObj) { for(i=0;i<chkObj.length;i++) { if(chkObj[i].checked) return true; } return false; } function CheckSubmit() { if(!CheckObject(document.all("type"))) { alert("Please select a type"); return false; } if(!CheckObject(document.all("color"))) { alert("Please select a color"); return false; } return true; } Never comment ur code. If it was hard to write, it should be hard to understand !!!
-
Include following 2 javascript functions & call CheckSubmit() on form submit. Hope this helps u.:~ function CheckObject(chkObj) { for(i=0;i<chkObj.length;i++) { if(chkObj[i].checked) return true; } return false; } function CheckSubmit() { if(!CheckObject(document.all("type"))) { alert("Please select a type"); return false; } if(!CheckObject(document.all("color"))) { alert("Please select a color"); return false; } return true; } Never comment ur code. If it was hard to write, it should be hard to understand !!!