Hi to all,


After comming alert, cursor should not go to the next field. i am a beginner to script functions. can any one give me solution .

<script>
function validateDate(strdate)
{
	if(strdate.length < 8 || strdate.length > 8)
	{
	alert("Error:Enter Valid Date");
	}
	else
	{
	ValidateNum(strdate);
	}
}
</script>

<html>
 <head>
  <title> New Document </title>
 </head>

 <body>
 Bhanu <input type="text" name ="bhanu" onblur = "validateDate(this.value);" >
 <input type="submit" value="submit">
  
 </body>
</html>

regards
Bhanu

use this line after your alert.

alert("Error:Enter Valid Date");
document.getElementById("num").focus();
return false;

"num" should be your next input filed id.

"onblue" event is sometimes tricky because it may not result what you want. If you want to use it, be more careful. Anyway, if you want it to be local, you could do it as followed...

<script>
// pass in the whole element for easier validation
function validateDate(elem) {
  var strdate = elem.value
  if(strdate.length != 8) {  // less than or greater than the same number means 'not equal'
    alert("Error:Enter Valid Date");
    elem.focus()  // force focusing to itself
  }
  else {
    ValidateNum(strdate);  // not sure what this would do...
  }
}
</script>

<html>
 <head>
  <title> New Document </title>
 </head>

 <body>
 Bhanu <input type="text" name ="bhanu" onblur = "validateDate(this);" >
 <input type="submit" value="submit">
  
 </body>
</html>
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.