...

View Full Version : onFocus



jlimited
02-03-2007, 04:23 AM
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.



<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

BWiz
02-03-2007, 04:29 AM
JavaScript

<script type="text/javascript">
<!--
function focusField(f-id)
{
window.document.getElementById(f-id).focus();
}
-->
</script>

Body tag

<body onload="focusField(text)">

Form tag


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

otaku149
02-03-2007, 04:55 AM
You meant


<body onload="focusField('text')">

Or simply use this:


<body onload="document.getElementById('sid').focus()">

<input type="text" id="sid" />



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum