Find jobs - Acs Student Loans - Free Advertising - Debt Consolidation - Debt Consolidation

PDA

View Full Version : Validation problem


MSK7
Feb 26th 2009, 4:26 am
In my form validation is applied for informing Invalid data entered in the field before submit the form instantly at the time of mistake.

After throwing the correct instant alert message of mistake ,

the Invalid data entered by user get selected but does not Erased

and invalid data remain selected after this.

please suggest me

what should done so that the invalid data entered should be Erased completely after giving Error alert message of "Invalide data" .

& the text field get empty for entering new valid data in it.

small code of my form is shown below:-



<html>
<head>

<script type="text/javascript">

function validate_required(form2)
{
if (form2.name.value=="")
{
alert("Please enter the Full Name");
document.form2.name.focus();
return false;
}
return true;
}


function checkName()
{

if (!isNaN(document.getElementById('name').value))
{
alert("Invalid numeric value entered! Please enter the Valid Name");
document.form2.name.focus();
return false;
}
return true;
}

</script>
</head>


<body>

<form name="form2" id="form2" onsubmit="return validate_required(this)" action="infosubmit2.php" method="post" >

Name : <input type="text" name="name" id="name" onkeyup="checkName()" size="40" />

</body>
</html>




Thanks & Regards.

lp1051
Feb 26th 2009, 7:33 am
Hi MSK7,

just add this before calling the focus() in both functions. That tells that the value of the form field called 'name' should be set to '' (empty string).

document.form2.name.value = '';

MSK7
Feb 27th 2009, 3:25 am
Hello sir,

Thanks for your precious Suggession for this problem.

Your guidance solved my problem .

Hope to get your precious suggessions & guidance in future also.


Thanks & Regards.