using onLoad() to focus login form- error handling

K

knot2afrayed

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?
 
M

Manifest Interactive

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
 
T

Thomas 'PointedEars' Lahn

Manifest said:
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
 
M

Manifest Interactive

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.
 
T

Thomas 'PointedEars' Lahn

Manifest said:

Are you referring to something?

<http://jibbering.com/faq/faq_notes/pots1.html#ps1Post>
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
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Sun, 26 Feb
2006 21:02:02 remote, seen in Thomas
'PointedEars' Lahn said:
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.
 
T

Thomas 'PointedEars' Lahn

Dr said:
JRS: In article <[email protected]>, dated Sun, 26 Feb
2006 21:02:02 remote, seen in Thomas


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):

(ignoring context)
(ad hominem attack)
(ad hominem attack)
(ad hominem attack)
(ad hominem attack,
ignoring context)
(ad hominem attack,
misinformation)
(ad hominem attack)
(ad hominem attack)
(ad hominem attack/bigotry,
misinformation)
(misinformation)
(misinformation, ad hominem attack)
(ad hominem attack)
(this one really is special)
(more bigotry)
(ad hominem attack)
(ad hominem attack, misinformation)
(ad hominem attack, calling a
recommendation part of some
imagined would-be dictatorship)
(misinformation)


PointedEars
 
M

Manifest Interactive

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
 
R

Randy Webb

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?
 
M

Manifest Interactive

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
 
R

Randy Webb

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.
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.
 
M

Manifest Interactive

Randy said:
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.


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.



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.


No. That will email the author and not post it to the newsgroup.


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.

Thanks friend.

- Peter Schmalfeldt
 
R

Randy Webb

Tony said the following on 3/10/2006 5:31 PM:
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 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top