john010117 Posted July 14, 2007 Share Posted July 14, 2007 First of all, I don't know what the thing is called that blinks inside a textarea. So if you could tell me what the name of that is, that'll be great. I'll called it a cursor for now. Here's the problem. Let's say I had a simple textarea with some values already filled in. Ex: Code: <textarea name="input1" rows="15" cols="75"> <!-- Cursor should go here --> ----- Original Message ----- From: blah To: Blah Date: Blah Blah Some Random Text </textarea> So, whenever a page loads, I need the "cursor" to be automatically at the beginning of the textarea (where "<!-- Cursor should go here -->" is). How would I go about doing that either in just HTML or Javascript? Link to comment https://forums.phpfreaks.com/topic/60006-solved-putting-the-cursor-at-the-beginning-of-the-textarea-on-page-load/ Share on other sites More sharing options...
ToonMariner Posted July 14, 2007 Share Posted July 14, 2007 bit of javascript... in your body tag put onload="document.getElementById('input1').focus();" Link to comment https://forums.phpfreaks.com/topic/60006-solved-putting-the-cursor-at-the-beginning-of-the-textarea-on-page-load/#findComment-298465 Share on other sites More sharing options...
john010117 Posted July 14, 2007 Author Share Posted July 14, 2007 So it'll be like: <body bgcolor="#000000" onload="document.getElementById('input1').focus();"> ? Thanks. I'll try that out. Link to comment https://forums.phpfreaks.com/topic/60006-solved-putting-the-cursor-at-the-beginning-of-the-textarea-on-page-load/#findComment-298473 Share on other sites More sharing options...
john010117 Posted July 14, 2007 Author Share Posted July 14, 2007 For some reason, it's not working. It doesn't "select" the field automatically (and yes, my browser has Javascript enabled). Link to comment https://forums.phpfreaks.com/topic/60006-solved-putting-the-cursor-at-the-beginning-of-the-textarea-on-page-load/#findComment-298478 Share on other sites More sharing options...
john010117 Posted July 15, 2007 Author Share Posted July 15, 2007 Never mind. I have to put the "id" attribute in the textarea. Thanks for that. Link to comment https://forums.phpfreaks.com/topic/60006-solved-putting-the-cursor-at-the-beginning-of-the-textarea-on-page-load/#findComment-298481 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.