View Full Version : How to type in a Form Field without clicking it - i.e like Google/Yahoo?
misohoni
Jun 13th 2005, 4:00 am
This may be an easy one and I used to be able to do this in old versions of DW, but how to make a field open (i.e. you can type in it straight away) without clicking on it first.
Examples - the search boxes in Yahoo/Google...you don't need to click on them before you type your search.
Thanks
tresman
Jun 13th 2005, 4:27 am
It's javascript, did you looked at google code?
you can do that:
<body onload="myfunction()">
now, betweeen the <head> and the </head> you have to add:
<script type="text/javascript">
<!--
function myfunction() {
this.focus()
};
// -->
</script>
This should work, but if not you reply here or do some test. I am not a javascript guru (I'm reallyyyyy far waya from) but this is basically the idea.
misohoni
Jun 13th 2005, 8:26 am
Ah I thought it was something I needed to add in the <input form part> thanks, I'll test it
cagintranet
Jun 22nd 2005, 4:42 am
Heres what i use:
add this onload statement to your <body> tag.
<body OnLoad="document.requestform.aname.focus();">
syntax is document.[formname].[fieldname that needs the focus].focus()
below is the input field that will be recieving the focus... see how the name of it is "aname" - same as in the onload statement?
<input type="text" name="aname" value="">
hope this helps
misohoni
Jun 22nd 2005, 7:52 am
thanks but didn't work for me.
tresman
Jun 22nd 2005, 8:24 am
Well Mishoni,
I thought you had already solved this problem. But look like not.
I think it didn't work cause you haven't read carefully what he said.
Please note this
syntax is document.[formname].[fieldname that needs the focus].focus()
And note now the [formname].
Give your form a name and it will work.
But if you do not want to think, find te code below
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>
</title>
</head>
<body onload="document.myform.myinput.focus()">
<form name="myform">
<input name="myinput" type="text" />
<input type="button" value="GO!" />
</form>
</body>
</html>
Is that easy. Look at "myfrom" and look at "myinput". Look too at the onload statement. It's that easy man.
cagintranet in fact solved your problem already.
misohoni
Jun 22nd 2005, 9:34 am
Err thanks for the beginneers run thru, your rcode didn't work for me though - I've got multi-layered dynamic tabs on my site same as Google/Yahoo and it doesn't pick it up. Here's the code I've been messing with but I don't think there's a solution. No Cagintranet's code gives JS errors...
<script>
<!--
function selector(){document.schina.q.focus();}
d=document;
// -->
</script>
</head>
<body onLoad=selector()>
tresman
Jun 22nd 2005, 10:56 am
can you please post the site so I can have look. Or pls pm.
misohoni
Jun 23rd 2005, 12:35 am
Thanks for the offer, I've spent a couple of hours on it and realised it's not worth it at this moment...is ok thanks for the help though.
webnp05
Jul 14th 2005, 9:23 pm
document.form.fieldname.focus() does not seem to work on Safari when i test it. Is anyone else having this trouble? Anyone can provide a solution please?
J.D.
Jul 15th 2005, 5:58 am
document.form.fieldname.focus() does not seem to work on Safari when i test it. Is anyone else having this trouble? Anyone can provide a solution please?Try this:
<body onload="document.forms.n1.n3.focus()">
<form name="n1">
<input name="n2"><input name="n3">
</form>
</body>
or this:
<body onload="document.getElemenetById("id3").focus()">
<form>
<input name="n2"><input name="n3" id="id3">
</form>
</body>
J.D.
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.