View Full Version : focusing on an image input
tyler jones
07-12-2002, 07:05 PM
I am trying to focus on an input type="image" when the page loads with something like...
<body onLoad="document.form1.imageTag.focus();">
I've tried many variations to the script, but when I try to focus on an image input, it just doesn't work. I get an error that it's null or not an object. However, if I change it's type from image to text, it works fine. Any ideas? Thanks.
joh6nn
07-12-2002, 09:30 PM
what browser does that happen in?
tyler jones
07-12-2002, 09:48 PM
Explorer version 6.0.2600.
joh6nn
07-13-2002, 12:50 AM
well, i don't know what to tell you. as far as i know, that should be working. can we see the code you're working with?
spybreak
04-11-2003, 06:06 PM
I have the same Problem.
When I dump my forms Elements with JavaScript I get:
name: form[save] index: 10
name: form[refresh] index: 9
name: page index: 8
name: form[screenName] index: 7
name: form[websiteUrl] index: 6
name: form[websiteName] index: 5
name: form[movieName] index: 4
name: form[bookAuthor] index: 3
name: form[bookName] index: 2
name: form[bandName] index: 1
name: form[quote] index: 0
But there are no <input type="image">'s in there, I have a bunch of them :/
beetle
04-11-2003, 06:24 PM
Sez right here (http://msdn.microsoft.com/workshop/author/dhtml/reference/collections/elements.asp) that input type=image are not part of the collection.
Give it an ID and access it via document.getElementById()
spybreak
04-11-2003, 07:53 PM
I can't seem to be able to focus an element by its Id.
that doesnt do it for some reason:
<html>
<body>
<form>
<input name="realName" id="realName">
</form>
<script language="JavaScript">
<!--
document.getElementById("realName").focus();
-->
</script>
</body>
</html>
beetle
04-11-2003, 07:55 PM
Works just peachy for me.
Browser?
spybreak
04-11-2003, 08:12 PM
IE 6
spybreak
04-11-2003, 08:14 PM
well... its working now.. strange. it didnt work when i posted that. or it seemed not to be working. strange. sorry
maybe im just stupid
spybreak
04-11-2003, 08:54 PM
Well. it didnt work again for some reason on the regular form I'm using (The one i posted was just to show)
What I had to do is:
document.getElementById("nameHere").focus();
window.focus(); <------- THIS
I dont know why, but now it works
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.