Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 23rd, 2004, 11:23 AM
Authorized User
 
Join Date: Feb 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default tabindexes don't work with onBlur function in Net

Hello,

I am having problems using NETSCAPE with the tabindexes after using the "onBlur" Javascript function. I have been looking and looking and I can't find what is wrong!!!.

Basically, I have the following:
- field1
- field2
- field3
- field4
...etc
Field 2 and field3 are inicially disabled.
What I want to do is:
- If I enter something in field1 => I want field2 and field3 to be automatically enabled.. and obviously I want the cursor to be on field2. Sounds easy right?

Now:
CASE 1: Field 1 is empty:
- I use the "tabulator" from field1.... and the cursor goes to field4: CORRECT.

CASE 2: Field1 is not empty:
- I use the "tabulator".... field3 and field4 are enabled .... but the cursor goes to field4!!!!!

It works perfectly with Explorer but not with Netscape 7.0

Could you help ?


Here is part of my coding:
....
Function initForm1(form)
{
var f1=form.field1.value;
if (!f1.match(/^(\s)*$/) )
{
form.field2.disabled=false;
form.field3.disabled=false;
form.field2.focus();
}
else
{
form.field2.disabled=true;
form.field2.value="";
form.field3.disabled=true;
form.field3.value="";
}
}

.....
Field1:
<input type=text name="field1" tabindex=3 onBlur="initForm1(this.form);"
<br>
Field2:
<input type=text name="field2" tabindex=4>
<br>
Field3:
<input type=text name="field3" tabindex=5>
<br>
Field4:
<input type=text name="field4" tabindex=6>
.....


 
Old November 23rd, 2004, 12:01 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Elisabeth,

I'm sure there are other ways to do this with Netscape, but this seems to work...

Code:
function initForm1(form)
{
    var f1=form.field1.value;
    if (!f1.match(/^(\s)*$/) ) 
    {
        form.field2.disabled=false;
        form.field3.disabled=false;
        setTimeout("document.forms." + form.name + ".field2.focus()", 1);
    }
    else
    {
        form.field2.disabled=true;
        form.field2.value="";
        form.field3.disabled=true;
        form.field3.value=""; 
    }

}
HTH,

Chris

 
Old November 23rd, 2004, 02:25 PM
Authorized User
 
Join Date: Feb 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't know what I have done wrong but it partially works!!!
Now, I did get the focus on field2 .... but if I use the tabulator on field2..... the cursor does not go to field3 but somewhere else!!!!



 
Old November 24th, 2004, 04:22 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Not sure what you're doing wrong without seeing the code, but the following works for me...
Code:
<html>

<head>
  <title></title>

<script type="text/javascript">
function initForm1(form)
{
    var f1=form.field1.value;
    if (!f1.match(/^(\s)*$/) ) 
    {
        form.field2.disabled=false;
        form.field3.disabled=false;
        setTimeout("document.forms." + form.name + ".field2.focus()", 1);
    }
    else
    {
        form.field2.disabled=true;
        form.field2.value="";
        form.field3.disabled=true;
        form.field3.value=""; 
    }

}
</script>

</head>

<body>

<form name="myForm">
Field1:
<input type=text name="field1" tabindex=3 onBlur="initForm1(this.form);" 
<br>
Field2:
<input type=text name="field2" tabindex=4 disabled="disabled">
<br>
Field3:
<input type=text name="field3" tabindex=5 disabled="disabled">
<br>
Field4:
<input type=text name="field4" tabindex=6>

<input type="button" onclick="this.form.field2.focus();" />
</form>

</body>

</html>
Cheers,

Chris

 
Old November 24th, 2004, 04:51 AM
Authorized User
 
Join Date: Feb 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Chris,
I have tried your script... it works but only for field2. I mean that once I am on field 2 and use the tabulator.... it does not go to field 3.
Once the fields are enabled, I need to be able to use the tabulator to go from field1 to field2 to field3 to field4.

Thanks for your help.

 
Old November 24th, 2004, 06:06 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Well I don't know what your "tabulator" is but Chris's page works for me in IE and Netscape with the tab button.



--

Joe (Microsoft MVP - XML)
 
Old November 24th, 2004, 07:48 AM
Authorized User
 
Join Date: Feb 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think I now understand the use of the button that focuses on field2.. but this is not what I exactly need.
I have tried Chris's page again (on Netscape 7.0) and this is what I exactly do:
 - Focus on field1
 - Write something on field1
 - Use tab (from field1) => goes to field2 => correct
 - Use tab (from field2) => goes to the button near field4 => but I want the cursor to go directly to field3.

 
Old November 24th, 2004, 07:58 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Elisabeth,

I had been using the button for testing only - you don't need it.

However, the tab works fine for me from field 2 to 3 in Netscape.

Can you post your code please?

Thanks,

Chris
 
Old November 24th, 2004, 08:24 AM
Authorized User
 
Join Date: Feb 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Chris!!
I think I know why we are having problems. When I tried your script, I first used the tabulator on field1 and then the cursor went to field4. After that I focused on field1, entered a value and used the tab, it went to field2 and using the tab from field2 the cursor went to field1 again!!.
Now if you enter a value the first time in field1 it works fine.

Anyway, here is my code:

<html>
<head>
<title></title>

<script type="text/javascript">

function disableFields()
{
 document.forms[0].field2.disabled=false;
 document.forms[0].field3.disabled=false;
}

function initForm1(form)
{
 var f1=form.field1.value;
 if (!f1.match(/^(\s)*$/) )
 {
   form.field2.disabled=false;
   form.field3.disabled=false;
   setTimeout("document.forms." + form.name + ".field2.focus()", 1);
 }
 else
 {
   form.field2.disabled=true;
   form.field2.value="";
   form.field3.disabled=true;
   form.field3.value="";
 }
}
</script>
</head>
<body onLoad=disableFields()>

<form name="myForm">
Field1:
<input type=text name="field1" tabindex=3 onBlur="initForm1(this.form);"
<br>
Field2:
<input type=text name="field2" tabindex=4 >
<br>
Field3:
<input type=text name="field3" tabindex=5 >
<br>
Field4:
<input type=text name="field4" tabindex=6>
</form>
</body>
</html>


 
Old November 24th, 2004, 08:59 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Elisabeth,

The code works fine for me, I did notice on closer inspection that the line
Code:
<input type=text name="field1" tabindex=3 onBlur="initForm1(this.form);"
has no closing ">" - so probably worth correcting that just in case.

In addition, you may want to modify your initForm1 method...
Code:
function initForm1(form)
{
    var f1=form.field1.value;
    if (!f1.match(/^(\s)*$/) ) 
    {
        form.field2.disabled=false;
        form.field3.disabled=false;
        setTimeout("document.forms." + form.name + ".field2.focus()", 1);
    }
    else
    {
        form.field2.disabled=true;
        form.field2.value="";
        form.field3.disabled=true;
        form.field3.value=""; 
        setTimeout("document.forms." + form.name + ".field4.focus()", 1);
    }

}
(extra line to set focus on field 4 after disabling 2 & 3 - otherwise you get nothing in focus in Netscape)

HTH,

Chris





Similar Threads
Thread Thread Starter Forum Replies Last Post
javaScript function in asp.net not work in firefox rsanuj ASP.NET 1.x and 2.0 Application Design 1 February 8th, 2007 11:37 AM
calling a codebehind function on onblur event vishnupriya.kamalakaram ASP.NET 1.0 and 1.1 Basics 2 July 7th, 2006 08:25 AM
How to call a codebehin function on onblur event?? kv Priya ASP.NET 1.0 and 1.1 Professional 1 June 14th, 2006 02:43 PM
can't seem to get the mail() function to work Graham76 BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 October 5th, 2004 01:59 PM
function that doesn't work hosefo81 PHP How-To 1 March 10th, 2004 03:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.