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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.