Forum Moderators: open

Message Too Old, No Replies

Focus() is not working in Netscape 7.0 Browser

It is working in IE

         

ksvijay

11:02 am on May 13, 2005 (gmt 0)

10+ Year Member



Hi the following code is working in IE, but the focus is not working in Netscpe.
If i am entering a number that is not integer, the cursor should be again in the text field.
But the netscape is not supporting the functionality. Pls help me .
--------------------------------------------------
<html>
<head>
<title>My Page</title>
</head>
<body>
<form name="myform" action="http://www.mydomain.com/myformhandler.cgi" method="POST">
<input type="text" name="text" maxlength="50" value="12" onblur="validateText(this,'text')">
</form>
</body>
</html>
<script language="JavaScript">
function validateText(form,pro){
var integer = /^\d+$/;
var numb=document.forms[0].text.value;

if(parseInt(numb)!=numb-0) {
alert("Please Enter Integer Only ok")
document.forms[0].text.focus();
}else{
if (window.RegExp &&!integer.test(myform.text.value)) {
document.forms[0].text.focus();
alert("Invalid integer value entered (regular expression)");
}else{
alert("U entered correct "+numb);
}
}
}
</script>

RonPK

11:21 am on May 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello ksvijay, welcome to WebmasterWorld.

Generally it's not a good idea to use names like 'text', 'hidden' or 'submit' for form elements, as they may refer to other elements or properties. Maybe that's why Netscape doesn't do what you want.

Bernard Marx

9:51 pm on May 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



By the way, you have a regular expression defined that will test for an integer.
You don't seem to be using it.

Change this:

if(parseInt(numb)!=numb-0)

To this:

if(! integer.test(numb) )

ksvijay

5:22 am on May 16, 2005 (gmt 0)

10+ Year Member



I tried all the ways according to the replies for this post, but the browser not supporting(Netscape)
the Focus().
Pls help me

Bernard Marx

7:12 am on May 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try changing the order of these two statements (after using a new name for 'text').

document.forms[0].text.focus();
alert("Invalid integer value entered (regular expression)");

Any good?

ksvijay

12:12 pm on May 16, 2005 (gmt 0)

10+ Year Member



Hi the code u told is not working.I changed the name, and if i enter like "12.00" the IE tells
"Invalid integer value entered (regular expression"

but this functionality also not supported by netscape, pls anybody try this code in Netscape and if u find any solution pls tell me

thanks

RonPK

1:30 pm on May 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Two remarks:

1. it may be smarter to use onchange() instead of onblur(). My Firefox gets into an endless loop with the combination of onblur() and alert().

2. valid HTML: put the <script> block in the <head> section of your page, or in the <body>, if you prefer.

No solution for the focus()-issue, sorry...