Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-03-2007, 03:23 AM   PM User | #1
jlimited
New Coder

 
Join Date: Sep 2006
Posts: 32
Thanks: 5
Thanked 0 Times in 0 Posts
jlimited is an unknown quantity at this point
onFocus

This is most likely a real easy questions to answer

When this form loads, eI would like the cursor to be in the input box.

Code:
<form action=/prep/index.php?add=y method="post">
<p>Church ID: 1<br>Survey 3 of 20</p>
<p>Survey Identification Number: <input type="text" name="sid"></p>
<input type="hidden" name="churchid" value="1">
<input type="hidden" name="count" value="3">
<input type="submit" name="do" value="Submit">
</form>
Thanks
jlimited
jlimited is offline   Reply With Quote
Old 02-03-2007, 03:29 AM   PM User | #2
BWiz
Regular Coder

 
BWiz's Avatar
 
Join Date: Mar 2006
Location: Sol System
Posts: 471
Thanks: 7
Thanked 21 Times in 21 Posts
BWiz is an unknown quantity at this point
JavaScript
Code:
<script type="text/javascript">
<!--
function focusField(f-id)
{
 window.document.getElementById(f-id).focus();
}
-->
</script>
Body tag
Code:
<body onload="focusField(text)">
Form tag
Code:
<form>
<input type="text" id="text" />
</form>
Try that, 'text' being the ID of the field you want focused onload. Not tested, but I used something like this a long time ago...
__________________
BWiz :: Happy Coding!
2006
2007 2008 2009
2010 2011
Irrational numbers make no sense.
BWiz is offline   Reply With Quote
Old 02-03-2007, 03:55 AM   PM User | #3
otaku149
Regular Coder

 
Join Date: May 2006
Posts: 181
Thanks: 0
Thanked 0 Times in 0 Posts
otaku149 is an unknown quantity at this point
You meant
Code:
<body onload="focusField('text')">
Or simply use this:
Code:
<body onload="document.getElementById('sid').focus()">

<input type="text" id="sid" />
__________________
Martial
http://getElementById.com
otaku149 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:14 PM.


Advertisement
Log in to turn off these ads.