[RESOLVED] Focus cursor in textbox on pageload
Hello,
I've got a working PHP-script. I'm trying to modify it so, that on pageload the cursor automatically goes in the textbox.
Does someone know what script I have to use to focus the cursor in the textbox on pageload and where I should place it in the following PHP-script? I'm a novice :eek2: so I blew my mind on this a few times :)
Here's the script (the script regarding the textbox mentioned above is red):
Code:
<?php
echo "
<html>
<head>
<link href=\"../../../CSS/HVB.css\" rel=\"stylesheet\" type=\"text/css\">
</head>
<body class=starturen>
<h1>Tijdregistratie:</h1>
<form action='leerling_aanmelden.php' method='post'>
<table border = 0 cellspacing = 2 cellpadding = 4>
<tr>
<td bgcolor='#D2E1F8'>Voer je loginnaam in: <input type='text' name='Loginnaam' size='15'/></td>
</tr>
<tr> <td bgcolor='#D2E1F8' align=right><input type='submit' value='Verder' /></td>
</tr>
</table>
</form>
</body>
</html>
";
?>
Thanks in advance for your help! My Supurb IT-friends let me down on this...
Re: Focus cursor in textbox on pageload
PHP does not do that kind of stuff. You want Javascript. Let me look for code for you.
Re: Focus cursor in textbox on pageload
Here you go:
HTML Code:
<?php
echo "
<html>
<head>
<link href=\"../../../CSS/HVB.css\" rel=\"stylesheet\" type=\"text/css\">
</head>
<body class=starturen>
<h1>Tijdregistratie:</h1>
<form action='leerling_aanmelden.php' name='login' method='post'>
<table border = 0 cellspacing = 2 cellpadding = 4>
<tr>
<td bgcolor='#D2E1F8'>Voer je loginnaam in: <input type='text' name='Loginnaam' size='15'/></td>
</tr>
<tr> <td bgcolor='#D2E1F8' align=right><input type='submit' value='Verder' /></td>
</tr>
</table>
</form>
</body>
</html>
";
?>
<script language="JavaScript">
<!--
document.login.Loginnaam.focus();
//-->
</script>
EDIT:
Also, avoid echo-ing HTML, especially big chunks like you are. Change it so that it goes to HTML and not PHP. If you need help with it, post the rest of your code.
Re: Focus cursor in textbox on pageload
Thanks for your help! I really appreciate your effort.
Re: Resolved: Focus cursor in textbox on pageload
There's actually no PHP there. dclamp is correct; only use <?php ... ?> around PHP code. The rest is just as per a regular HTML document.
By the way, an easier method of marking a thread resolved is to use the Thread Tools menu, above the first post.
Welcome to VBForums, too.
Re: Resolved: Focus cursor in textbox on pageload
Thanks for the rep :)
:wave: welcome to vbf