Forum Moderators: open
var tempobj=which.elements[i];
if (tempobj.name.substring(0,8)=="required") {
if (((tempobj.type=="text"¦¦tempobj.type=="textarea")&&
tempobj.value=='')¦¦(tempobj.type.toString().charAt(0)=="s"&&
tempobj.selectedIndex==0)) {
pass=false;
break;
I have tried changing textarea to checkbox but it allows the submission with or without a tick as the value isn't picked up, the checkbox name is requiredterms, the word required gets caught by the validation script, any ideas? as usual the forum broke the pipes, they are pipes.
Thanks in advance
[pre]function checkForm(){
var formId ="formID";
var checkID="submit";
return document.forms[formId][checkID].checked;
}[/pre][pre]<form id="formID" onsubmit="return checkForm();">
<input type="checkbox" name="submit">
<input type="submit" value="Submit">
</form>[/pre]
Its not just for a checkbox, theres plenty of other elements it currently checks, I just need to add a checkbox to be validated.
I have this snippet
(tempobj.type=="checkbox")
{
eval(tempobj.checked=0)
}
How/where do I add it to the above javascript so it gets validated?
Edit
Ok worked it out, just added this line to catch the checkbox
¦¦
(tempobj.type=="checkbox"&&tempobj.checked==0)So it now looks like
((tempobj.type=="text"¦¦tempobj.type=="textarea")&&tempobj.value=='')
¦¦
(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==0)
¦¦
(tempobj.type=="checkbox"&&tempobj.checked==0)
)
Works as expected
[edited by: wheelie34 at 4:17 pm (utc) on Feb. 16, 2008]
eval(tempobj.checked=0)
if (((tempobj.type=="text" ¦¦ tempobj.type=="textarea") &&
tempobj.value=='') ¦¦ (tempobj.type.toString().charAt(0)=="s" &&
tempobj.selectedIndex==0))
if (
((tempobj.type=="text" ¦¦ tempobj.type=="textarea" )&&tempobj.value=='') ¦¦ //For text areas
(tempobj.type.toString().charAt(0)=="s" && tempobj.selectedIndex==0)¦¦ //For selects
(tempobj.type=="checkbox" && tempobj.checked) //For checkboxes
)