Hi there,
Got some form validation but doesn't seem to even be running through it.
First off the form is displayed, if you click in 'Name:' the 'ID:' box disappears so that you cant type in both, after it disappears (and vice versa), the validation should check its correct, but doesnt.
form
<form action="delete.php" method="post" onSubmit="return checkDel()" >
<table width="200" border="0" cellpadding="2" cellspacing="0" class="adforms">
<tr>
<th width="40">Name: </th>
<td width="152" align="left"><input type = "text" name = "dname" size="15" id="delnain" onclick="hideid()"/></td>
</tr>
<tr>
<th>ID: </th>
<td align="left"><input type = "text" name = "did" size="2" id="delidin" onclick="hidena()"/></td>
</tr>
<tr>
<td></td>
<td align="right"><input type="submit" value="Delete item"/></td>
</tr>
</table>
</form>
hide box code- works fine
<script language="javascript">
function hidena()
{
document.getElementById('delnain').style.visibility = "hidden";
}
function hideid(){
document.getElementById('delidin').style.visibility = "hidden";
document.getElementById('delidin').value = 0;
}
</script>
form validation- doesnt work
<script language="text/javascript">
function checkDel(){
var dname = document.getElementById('delnain');
var did = document.getElementById('delidin');
var div = document.getElementById('errormsg');
var lets = /^[a-zA-Z\s]+$/;
var nums = /^[0-9]+$/;
if(dname.style.visibility = "hidden"){
if(did.value == ''){
div.innerHTML= "<b>Please fill in the an ID</b>";
did.focus();
return false;}
else if(did.value.match(nums)){
return true;}
else{
div.innerHTML= "<b>Only numbers please</b>";
did.focus();
return false;}}
else{
if((dname.value == '') || (dname.value == ' ')){
div.innerHTML= "<b>Please fill in the item name</b>";
dname.focus();
return false;}
else if(dname.value.match(lets)){
return true;}
else{
div.innerHTML= "<b>Only letters please</b>";
dname.focus();
return false;}
}
}
</script>
All posts are appreciated. Thanks in advance