Jump to content

Setting focus to a form text box


dmccabe

Recommended Posts

I have a simple form (two text boxes and a submit button) and I want it so when he page loads the cursor is already in the first of the 2 text boxes, can anyone point me in the right direction

 

		<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="login">
		<div id="login_top">
			<div id="login_box">
				<input type="text" name="ldapname" size="30"><br /><br />
				<input type="password" name="ldappass" size="30">
			</div>
		</div>
		<div id="login_bottom">
			<div id="login_btn">
				<input type="submit" value="Login" name="submit">  <input type="submit" value="Cancel" name="submit">
			</div>
		</div>
	</div>
	</form>

Link to comment
https://forums.phpfreaks.com/topic/119801-setting-focus-to-a-form-text-box/
Share on other sites

Thanks again for the fast reply.

 

Doesnt seem to be working though.

 

I have it like this at the moment:

 

<body onload="document.getElementById(\"text_area_id\").focus()">
	<div id="login">
		<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="login" id="ldapname">
		<div id="login_top">
			<div id="login_box">
				<input type="text" name="ldapname" size="30"><br /><br />
				<input type="password" name="ldappass" size="30">
			</div>
		</div>
		<div id="login_bottom">
			<div id="login_btn">
				<input type="submit" value="Login" name="submit">  <input type="submit" value="Cancel" name="submit">
			</div>
		</div>
	</div>
	</form>

 

however I also tried changing the "text_area_id" part to "ldapname" and it didnt work there either.

 

Any ideas?

Archived

This topic is now archived and is closed to further replies.

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