0

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

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Taywin
0

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.

Edited by Shanti C: n/a

0

"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>

Edited by Taywin: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.