View Full Version : Setting Focus Automatically on Form Fields
Uzair
09-29-2006, 08:51 AM
There are many ways for setting focus on form fields. I'm actually looking for some code that automatically detects if there is any form on the page & then automatically sets the focus to the first field of the form.
No need of putting Form Name & Field Name in Javascript.
Is there any way to do this ???
Please Help!!!
dungsport
09-29-2006, 09:20 AM
All you need is this piece of code:
<script language="JavaScript">
<!--
objs = document.getElementsByTagName('input');
for(i=0; i<objs.length; i++) {
if (objs[i].type == 'text') {
objs[i].focus();
break;
}
}
//-->
</script>
It will focus the first textbox in the page. Modify it a bit to get the first Combo, textarea, so on...
Uzair
09-29-2006, 09:22 AM
u mentioned PHP CODE. wot does this mean ? Can I only use this code in PHP pages or HTML too ???
dungsport
09-29-2006, 10:00 AM
OMG, you didn't mention you were a newbie, j/k :D
Putting thing in PHP tag make it colourful and readable. Please notice that they are in <script> tag.
Cheers mate,
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.