homepage Welcome to WebmasterWorld Guest from 54.211.68.132
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

    
A form input focusing issue
If what I'm going to ask is even possible...
Golden_Sin




msg:4362065
 6:48 pm on Sep 13, 2011 (gmt 0)

I've been wondering whether it is possible to make a text input to be focused immediately when the page is opened. With focusing, without a better word to use, I mean that the text field is made writeable. Sorry for my unconsciousness about the right term.

If you understood me and think this is possible, I would appreciate help.

 

Marshall




msg:4362081
 7:48 pm on Sep 13, 2011 (gmt 0)

Depending on your form and field names, add this in the page:

<body onload="document.emailform.name.focus()">

Where "emailform" is, put your form name.
Where "name" is, put the name of the field you want to focus.

Marshall

Golden_Sin




msg:4362355
 12:47 pm on Sep 14, 2011 (gmt 0)

I tried it and it worked. Thank you.

rocknbil




msg:4362422
 3:57 pm on Sep 14, 2011 (gmt 0)

While that works, it puts scripting into your page markup. Moving forward, separating presentation and scripting from content, this is probably better.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Untitled</title>
<script type="text/javascript">
window.onload=function() {
if (document.getElementById('email-field')) {
document.getElementById('email-field').focus();
}
};
</script>
</head>
<body>
<form action'"whatever">
<p><label for="email-field">Email:</label> <input type="text" name="email" id="email-field"></p>
</form>
</body>
</html>

Then you can put your JS in a separate file and do

<script type="text/javascript" src="myjs.js"></script>

instead.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved