This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes onblur/onchange workaround needed... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "onblur/onchange workaround needed..." Watch "onblur/onchange workaround needed..." New topic
Author

onblur/onchange workaround needed...

Vijay S. Rathore
Ranch Hand

Joined: Oct 29, 2001
Posts: 449
Hi,
I have a series of text boxes and I have to warn the users about the value of these boxes with an confirm. Based on the selection from the warning I have to put focus back to the selected box.
When the page loads, the boxex can have values, not satisfying the condition.
Well onchange event somehow dosen't put the focus back on my field if I select cancel from my confirm box.
When I use onblur event it puts my screen into an infinite loop till ok is pressed.

Here is the sample of code that I am trying to explain. Does anyone know a workaround or any other way of doing the same.
<html>
<head>
<title>onblur Test</title>
<script>
function checkWeight(curObj){
if(curObj.value > 10){
if(!confirm("The object is overwight. Are you sure you want to proceed...?")){
curObj.select();
curObj.focus();
}
}
}
</script>
</head>
<body>
<form>
<p><input type="text" size="20" name="T1" value="23" onfocus="this.select();" onblur="checkWeight(this);">
<input type="text" size="20" name="T2" value="25" onfocus="this.select();" onblur="checkWeight(this);">
<input type="text" size="20" name="T3" value="27" onfocus="this.select();" onblur="checkWeight(this);"></p>
</form>
</body>
</html>


SCJP, SCJD, SCWCD1.4, IBM486, IBM484, IBM 483, IBM 287, IBM141, IBM Certified Enterprise Developer - WebSphere Studio, V5.0
Author of IBM 287 Simulator Exam
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
if you are forcing people to place the right string into the field then why are you using a confirm? You can use an alert instead.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: onblur/onchange workaround needed...
 
Similar Threads
what's wrong with this script
Cross browser issues
problem with on change event
How can i trace this..
multilingual in java script