Results 1 to 6 of 6

Thread: [RESOLVED] Focus cursor in textbox on pageload

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2007
    Posts
    2

    Resolved [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 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...
    Last edited by klaas_h; Jul 20th, 2007 at 03:55 PM.

  2. #2
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    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.
    My usual boring signature: Something

  3. #3
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    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.
    My usual boring signature: Something

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2007
    Posts
    2

    Re: Focus cursor in textbox on pageload

    Thanks for your help! I really appreciate your effort.

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  6. #6
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Resolved: Focus cursor in textbox on pageload

    Thanks for the rep

    welcome to vbf
    My usual boring signature: Something

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width