By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,144 Members | 872 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,144 IT Pros & Developers. It's quick & easy.

using onLoad() to focus login form- error handling

P: n/a
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
Share this Question
Share on Google+
13 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.