473,414 Members | 1,667 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

using onLoad() to focus login form- error handling

I am trying to fix error- object does not exist- I want it possible to
allow object not to exist.

I am writing a script on a page that may or may not include a login
form. For example-after a visitor logs in, the login form is no longer
on the page, but other content is still there.
I want to bring focus to the login form using the onLoad in the body
tag.....but if the login form does not exist, I do not want to perform
this function.

The following code works fine for focusing the cursor on to the login
form.

(code)
<html>
<head>
<title>
Testing Javascript
</title>
<script type="text/javascript">
<!--
function addcursor ()
{
if (document.login) {
document.login.username.focus();
}
}
//-->
</script>
</head>
<body OnLoad ="addcursor()">

<form name="login" id="login" action="" method="post">
<input type = "text" name="username" id="username" />
<input type="password" name="password" />

</form>
</body>
</html>
(end code)

But if you remove the form in the body section from the code, an error
"object does not exist or is null" results.
I am looking for a way to avoid this error.
Any suggestions?

Feb 26 '06 #1
13 3987
Greetings,

You might juse want to move the function call out of the body tag and
place it at the bottom of the page that has the form on it. You can
still do an onload call as follows:

<script type="text/javascript">
window.onload = function() {
document.login.username.focus();
}
</script>

Place this at the bottom of your page that has the form and it will do
the same as what you currently have. Plus this will keep you frma
heading towards a script that disables javascript alerts.

I hope this helped,

- Peter Schmalfeldt
Manifest Interactive

Feb 26 '06 #2
Manifest Interactive wrote:
You might juse want to move the function call out of the body tag and
place it at the bottom of the page that has the form on it. You can
still do an onload call as follows:

<script type="text/javascript">
window.onload = function() {
document.login.username.focus();
}
</script>

Place this at the bottom of your page that has the form [...]


No, don't. Use

<body onload="document.forms['login'].elements['username'].focus();">
...
</body>

instead.
PointedEars
Feb 26 '06 #3
This will cause the same problem that this user was having. Since the
code would be placed on every page, some pages will not have the form
named "login" which obviously would also not have the element
"username". The script will generate an error when the page is loaded,
which is what the original post requested to fix.

Feb 26 '06 #4
Manifest Interactive wrote:
This
Are you referring to something?

<http://jibbering.com/faq/faq_notes/pots1.html#ps1Post>
<http://safalra.com/special/googlegroupsreply/>
will cause the same problem that this user was having. Since the
code would be placed on every page, some pages will not have the form
named "login" which obviously would also not have the element
"username". The script will generate an error when the page is loaded,
which is what the original post requested to fix.


But you did not fix it at all, in fact your code would cause the exact
same error in that case. A fix would have to either include the code
conditionally (if generated server-side) or execute the included code
conditionally if it was always included. For the latter, a feature
test such as

<head>
...
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
function isMethodType(s)
{
return (s == "function" || s == "object");
}

function focusControl()
{
var o = document.forms['login'];
if (o && (o = o.elements) && (o = o['username'])
&& isMethodType(typeof o.focus))
{
o.focus();
}
}
</script>
...
</head>

<body onload="focusControl();">
...
</body>

would suffice.

BTW: It would be appreciated if you stopped advertising for
your company and get yourself as an individual a name here.
PointedEars
Feb 26 '06 #5
JRS: In article <18****************@PointedEars.de>, dated Sun, 26 Feb
2006 21:02:02 remote, seen in news:comp.lang.javascript, Thomas
'PointedEars' Lahn <Po*********@web.de> posted :

BTW: It would be appreciated if you stopped advertising for
your company and get yourself as an individual a name here.


CONTROL FREAK WARNING.

See thread Assoziative Arrays in Javascript in
newsgroup de.comp.lang.javascript.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME ©
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Feb 27 '06 #6
Dr John Stockton wrote:
JRS: In article <18****************@PointedEars.de>, dated Sun, 26 Feb
2006 21:02:02 remote, seen in news:comp.lang.javascript, Thomas
'PointedEars' Lahn <Po*********@web.de> posted :

BTW: It would be appreciated if you stopped advertising for
your company and get yourself as an individual a name here.
CONTROL FREAK WARNING.


Do not feed the troll.
See thread Assoziative Arrays in Javascript in
newsgroup de.comp.lang.javascript.


See the following of his messages (which are, unfortunately,
the majority of all of his messages this year; it is worth
to have a look at his messages of the previous year, too):

news:0$**************@merlyn.demon.co.uk (ignoring context)
news:P8**************@merlyn.demon.co.uk (ad hominem attack)
news:ot**************@merlyn.demon.co.uk (ad hominem attack)
news:QP**************@merlyn.demon.co.uk (ad hominem attack)
news:4M**************@merlyn.demon.co.uk (ad hominem attack,
ignoring context)
news:gu**************@merlyn.demon.co.uk (ad hominem attack,
misinformation)
news:50**************@merlyn.demon.co.uk (ad hominem attack)
news:l5**************@merlyn.demon.co.uk (ad hominem attack)
news:p4**************@merlyn.demon.co.uk (ad hominem attack/bigotry,
misinformation)
news:$M**************@merlyn.demon.co.uk (misinformation)
news:zw**************@merlyn.demon.co.uk (misinformation, ad hominem attack)
news:eh**************@merlyn.demon.co.uk (ad hominem attack)
news:0m**************@merlyn.demon.co.uk (this one really is special)
news:hP**************@merlyn.demon.co.uk (more bigotry)
news:4M**************@merlyn.demon.co.uk (ad hominem attack)
news:vQ**************@merlyn.demon.co.uk (ad hominem attack, misinformation)
news:08**************@merlyn.demon.co.uk (ad hominem attack, calling a
recommendation part of some
imagined would-be dictatorship)
news:sq**************@merlyn.demon.co.uk (misinformation)
PointedEars
Feb 28 '06 #7
Greetings,

What's amusing about this post, is that every "bad" thing you are
pointing fingers at Dr John for seem to be when he is putting you in
your place for displaying aggressive/inappropriate behavior. Almost all
of the links you found are articles you were apart of. Maybe... just
maybe, it is you that is the problem my friend. Chill with the
attitude, we are all here to help each other. No need to behave the way
you are consistently behaving in your posts.

- Peter Schmalfeldt

Thomas 'PointedEars' Lahn wrote:
Dr John Stockton wrote:
JRS: In article <18****************@PointedEars.de>, dated Sun, 26 Feb
2006 21:02:02 remote, seen in news:comp.lang.javascript, Thomas
'PointedEars' Lahn <Po*********@web.de> posted :

BTW: It would be appreciated if you stopped advertising for
your company and get yourself as an individual a name here.


CONTROL FREAK WARNING.


Do not feed the troll.
See thread Assoziative Arrays in Javascript in
newsgroup de.comp.lang.javascript.


See the following of his messages (which are, unfortunately,
the majority of all of his messages this year; it is worth
to have a look at his messages of the previous year, too):

news:0$**************@merlyn.demon.co.uk (ignoring context)
news:P8**************@merlyn.demon.co.uk (ad hominem attack)
news:ot**************@merlyn.demon.co.uk (ad hominem attack)
news:QP**************@merlyn.demon.co.uk (ad hominem attack)
news:4M**************@merlyn.demon.co.uk (ad hominem attack,
ignoring context)
news:gu**************@merlyn.demon.co.uk (ad hominem attack,
misinformation)
news:50**************@merlyn.demon.co.uk (ad hominem attack)
news:l5**************@merlyn.demon.co.uk (ad hominem attack)
news:p4**************@merlyn.demon.co.uk (ad hominem attack/bigotry,
misinformation)
news:$M**************@merlyn.demon.co.uk (misinformation)
news:zw**************@merlyn.demon.co.uk (misinformation, ad hominem attack)
news:eh**************@merlyn.demon.co.uk (ad hominem attack)
news:0m**************@merlyn.demon.co.uk (this one really is special)
news:hP**************@merlyn.demon.co.uk (more bigotry)
news:4M**************@merlyn.demon.co.uk (ad hominem attack)
news:vQ**************@merlyn.demon.co.uk (ad hominem attack, misinformation)
news:08**************@merlyn.demon.co.uk (ad hominem attack, calling a
recommendation part of some
imagined would-be dictatorship)
news:sq**************@merlyn.demon.co.uk (misinformation)
PointedEars


Mar 9 '06 #8
Manifest Interactive said the following on 3/9/2006 12:44 PM:
Greetings,

What's amusing about this post, is that every "bad" thing you are
pointing fingers at Dr John for seem to be when he is putting you in
your place for displaying aggressive/inappropriate behavior. Almost all
of the links you found are articles you were apart of. Maybe... just
maybe, it is you that is the problem my friend. Chill with the
attitude, we are all here to help each other. No need to behave the way
you are consistently behaving in your posts.


Could you at least refrain from top-posting though?

Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 10 '06 #9
Greetings,

Time for a silly question. How do I keep from top posting? In the tree
view my last post shows up as item number 8. That post I selected "show
option" and then clicked "Reply". Other times I just clicked the link
under the post I wanted to reply to by clicking the link "> Reply".
Should I be clicking "Reply to Author" in show options instead?

I've been told I was doing in wrong both ways I have tried it. It would
be nice to know what I am doing wrong since it appears just fine when I
look at it in tree view in google groups.

Thanks for your help.

- Peter Schmalfeldt

Mar 10 '06 #10
Manifest Interactive said the following on 3/10/2006 8:29 AM:

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.
<URL: http://www.safalra.com/special/googlegroupsreply/ >
Greetings,

Time for a silly question. How do I keep from top posting?
When you reply, you move your cursor down below what you are replying
to. Then your reply will look similar to mine where my reply is
inter-leaved into what I am replying to.

In the tree view my last post shows up as item number 8. That post
I selected "show option" and then clicked "Reply". Other times I just
clicked the link under the post I wanted to reply to by clicking the
link "> Reply".
Clicking the link "Reply" won't quote what you are replying to - as you
did on this post. Use the Show Option > Reply so it quotes what you are
replying to.
Should I be clicking "Reply to Author" in show options instead?
No. That will email the author and not post it to the newsgroup.
I've been told I was doing in wrong both ways I have tried it. It would
be nice to know what I am doing wrong since it appears just fine when I
look at it in tree view in google groups.


What you have to remember is that this isn't Google Groups. Google
Groups is nothing but a web based interface to post to Usenet. I haven't
looked in Google Groups for a while, I use a newsreader to read Usenet.

The main problem with Google Groups is that people think it is a "Forum"
of it's own when it isn't. And the fact that Google makes it hard to
quote/reply properly.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 10 '06 #11

Randy Webb wrote:
Manifest Interactive said the following on 3/10/2006 8:29 AM:

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.
<URL: http://www.safalra.com/special/googlegroupsreply/ >
Greetings,

Time for a silly question. How do I keep from top posting?


When you reply, you move your cursor down below what you are replying
to. Then your reply will look similar to mine where my reply is
inter-leaved into what I am replying to.

In the tree view my last post shows up as item number 8. That post
I selected "show option" and then clicked "Reply". Other times I just
clicked the link under the post I wanted to reply to by clicking the
link "> Reply".


Clicking the link "Reply" won't quote what you are replying to - as you
did on this post. Use the Show Option > Reply so it quotes what you are
replying to.
Should I be clicking "Reply to Author" in show options instead?


No. That will email the author and not post it to the newsgroup.
I've been told I was doing in wrong both ways I have tried it. It would
be nice to know what I am doing wrong since it appears just fine when I
look at it in tree view in google groups.


What you have to remember is that this isn't Google Groups. Google
Groups is nothing but a web based interface to post to Usenet. I haven't
looked in Google Groups for a while, I use a newsreader to read Usenet.

The main problem with Google Groups is that people think it is a "Forum"
of it's own when it isn't. And the fact that Google makes it hard to
quote/reply properly.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


Thanks friend.

- Peter Schmalfeldt

Mar 10 '06 #12
Randy Webb wrote:

What you have to remember is that this isn't Google Groups. Google
Groups is nothing but a web based interface to post to Usenet. I haven't
looked in Google Groups for a while, I use a newsreader to read Usenet.
I HAD to use Google Groups for a couple months. I hated it.

I now am able to use a proper newsreader, and I'm much happier. I still
hate Google Groups, and don't use it at all.
The main problem with Google Groups is that people think it is a "Forum"
of it's own when it isn't. And the fact that Google makes it hard to
quote/reply properly.


The main problem with Google Groups is that they thought it would be a
good idea to include usenet. I'm beginning to wonder if Google has been
taking lessons from AOL...
Mar 10 '06 #13
Tony said the following on 3/10/2006 5:31 PM:
Randy Webb wrote:

What you have to remember is that this isn't Google Groups. Google
Groups is nothing but a web based interface to post to Usenet. I
haven't looked in Google Groups for a while, I use a newsreader to
read Usenet.


I HAD to use Google Groups for a couple months. I hated it.

I now am able to use a proper newsreader, and I'm much happier. I still
hate Google Groups, and don't use it at all.


For people that have no other access, it is fine. As long as you are
aware of it's shortcomings. Quoting being the biggest one.
The main problem with Google Groups is that people think it is a
"Forum" of it's own when it isn't. And the fact that Google makes it
hard to quote/reply properly.


The main problem with Google Groups is that they thought it would be a
good idea to include usenet. I'm beginning to wonder if Google has been
taking lessons from AOL...


I don't think they "included Usenet" as much as they "overlayed" it.
Google Groups was the premier archive of Usenet (and it still is). As
for AOL, AOL offered Usenet for a long time and stopped. It had its flaw
as well but if you were aware of them then you could work around them.
Using AOL as the connection you couldn't use anything but AOL's Usenet
unless you went to a web based access.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 11 '06 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Gordan | last post by:
Hi! I have a very simple form and the idea is that when the page loads the focus is set on the first textfield so that the user can start typing immediately without pressing the tab key. so I...
1
by: Richard Bell | last post by:
Why doesn't this seem to work? var win; // window handle function onloadfunction( arg ){ // replace cnn with google win.navigate( "http://www.google.com" );// never executes } win =...
1
by: reneecccwest | last post by:
hello, is there any way to indicte a cursor on the first text user input when a page loads without using onload in the body tag?
2
by: dsnyder | last post by:
This HTML has a bit of Javascript at the end that puts the initial focus on the userID field. It works great on Windows2000 running IE6, but the initial focus never goes to the userID field on...
1
by: Zvonko | last post by:
Hi! As mentioned in title. How to do it? Thanks Zvonko
2
by: Diogo Alves - Software Developer | last post by:
Hi, I have a login windows that appears after the main application starts, my problem is that when the login window appears it loses the focus and became deactivated... I've tryied to put...
2
by: Muhammad Ahsin Saleem | last post by:
hi i want to make a login form for my vb.net application. in it login form is displayed in mdi form and must has the focus on it. i have done it but focus on login form is not there user can...
0
by: supern | last post by:
this is my perl script saved as login.pl #!c:/perl/bin/perl.exe $basedir="c:/program files/apache software foundation/apache2.2/cgi-bin"; $datafile="regstr.txt"; $name=$in{'login'};...
4
by: Jason | last post by:
Hi, Here's the scenario: I have a web application that has window A and window B. A user has both window A and B open - window A is in the foreground and window B is behind it. If the...
11
by: slinky | last post by:
I'm trying to simply set the focus of "txtUserName" upon opening this login form. I put in some Javascript but it is not working. Any ideas? Thanks! <%@ Page Language="vb"...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.