473,320 Members | 1,940 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,320 software developers and data experts.

Error: document.getElementById("ff") has no properties

Hi

I want a form field to be selected when the page loads.

But I get the error message
Error: document.getElementById("ff") has no properties

any ideas what I am doing wrong?

code below
cheers Dave
<script type="text/javascript">
function setfocus()
{
document.getElementById('ff').focus();
}
window.onload = setfocus();
</script

<form>
<input type="text" id="ff" >
</form>

Nov 27 '06 #1
6 4566

li********@yahoo.com.au wrote:
Hi

I want a form field to be selected when the page loads.

But I get the error message
Error: document.getElementById("ff") has no properties

any ideas what I am doing wrong?
Passing the result of setfocus(), rather than a reference (see below).
>
code below
cheers Dave
<script type="text/javascript">
function setfocus()
{
document.getElementById('ff').focus();
Nothing to do with your problem, but it is considered better to use the
forms collection rather than getElementById - it is more widely
supported and faster. You should also test for the focus method before
trying to call it:

var el = document.forms[0].elements['ff'];
if (el.focus) el.focus();

}
window.onload = setfocus();
Your issue is here:

window.onload = setfocus; // Remove ()

[...]

--
Rob

Nov 27 '06 #2
Your issue is here:
>
window.onload = setfocus; // Remove ()

thanks for the answer, my brain was starting to melt
Dave

Nov 27 '06 #3
li********@yahoo.com.au wrote:
I want a form field to be selected when the page loads.
any ideas what I am doing wrong?
window.onload = setfocus();
should be:

window.onload = setfocus;

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Nov 27 '06 #4
solution 1 window.onload = setfocus;
solution 2
function window.onload()
{
document.getElementById("ff").focus();
}
Matt Kruse wrote:
li********@yahoo.com.au wrote:
I want a form field to be selected when the page loads.
any ideas what I am doing wrong?
window.onload = setfocus();

should be:

window.onload = setfocus;

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Nov 27 '06 #5
ih*********@gmail.com wrote:
solution 1 window.onload = setfocus;
solution 2
function window.onload()
{
document.getElementById("ff").focus();
}
Not a solution really as a property accessor in the position where an
Identifier is expected in a function declaration is a syntax error
(which is tolerated in IE but won't pass many other browsers without
complaint).

Richard.

Nov 27 '06 #6
Awsome! This thread helped me! Thanks guys!

Dec 5 '06 #7

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

Similar topics

22
by: David. E. Goble | last post by:
Hi All; I have a few of these; sigsImages="sigs/finished1.jpg" sigsImages="sigs/foghorn.jpg" lower I have;
1
by: dasayu | last post by:
Hi, I have a custom object called gridWidget. I am consistantly getting an error in FireFox when I click on an href, which calls a function defined on the object. The generated link looks similar...
3
by: Aaron | last post by:
I'm trying to parse a table on a webpage to pull down some data I need. The page is based off of information entered into a form. when you submit the data from the form it displays a...
60
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I prompt a "Save As" dialog for an accepted mime type?...
4
by: dr1ft3r | last post by:
Hey guys, I'm building a site for a landscaping business down the street and can't seem to get part of the code functioning correctly. The code fails on line 68 where I make a reference to an...
3
by: karprix | last post by:
Hi, I am working on a webapplication,( with Ajax & JSF) where I want to retrieve the value present in a <t:inputText id="starttimeScheduler" value="#{scheduledJobCreateEdit.startTimeDate}"...
7
by: dennis.sprengers | last post by:
I am trying to write an editor object, which adds some functionality and a toolbar to every textarea with a "form-textarea" class. Both FF and IE generate an error in line 20...
6
by: cleary1981 | last post by:
I have adapted code from http://dunnbypaul.net/js_mouse/ I want to use a button to create new draggable divs but i keep getting error "is null or not an object" heres the code <html> <head>...
2
by: ChrisLA | last post by:
Hi; I've seen lots of discussion & disagreement on this issue, so any good explanation would be appreciated. Some people seem to think that "document.GetElementByID("MyName").submit(); should...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.