Jump to content

[SOLVED] Cursor started in Text box on load


clang

Recommended Posts

I know this is probably a stupidly simple question, so I'm sorry in advance. I've tried looking around here and google to find a solution but came up empty handed. May my google-foo is not what it used to be.

 

Basically I have a form, made in html, with PHP processing it. I would like the first text box on the page, to be selected on page load, so that I start typing right away, with out having to use my mouse to click on the text box to place the cursor inside it.

Suggestions?

I continued looking and found something a bit helpful:  http://www.htmlgoodies.com/beyond/javascript/article.php/3471131#code for those that are interested.

But this requires me to include the name of that object, in this case a text box, in the body. Is there another way to handle this? I ask because all of my pages call a php function to get the body and the name of that text box has the need to be different on various pages.

 

maybe a this.focus() in the <input> tag?

Ha! Thanks everyone  :P

 

I kept looking and figured it out.

For anyone that needs to know this, another option to onload is the following

<script type="text/javascript">
document.form.item.focus();
</script>

 

Where form is the name of your form, and item is the name of the object you would like highlighted first.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.