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

i have modified your code . try this:

<div id="errormsg"></div>
<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>
<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>
<script language="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]+$/;
alert(dname.style.visibility);
alert(did.style.visibility);
if(dname.style.visibility=='' && did.style.visibility=='')
{
	div.innerHTML= "<b>Please fill ID or Name</b>";
	return false;
}
else
{
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>

OMG, that worked great, thanks very much.
I'll have a read through it and see where I can pickup more knowledge

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.