Page 1 of 1

Can't get this code right

Posted: Thu Oct 06, 2011 9:13 am
by Lonestarjack
What is the correct code ?

Code: Select all

<?php echo '<input class="x"  
	onfocus="HideContent("btn")" 
	name="username" 
	type="text" 
	id="username" 
	value= ' . $user . ' >';
	?>
It seems to fail around "btn" with a parse error.
$user has been defined.
HideContent is already defined.

Re: Can't get this code right

Posted: Thu Oct 06, 2011 9:23 am
by Celauran

Code: Select all

<?php

echo "<input class=\"x\"  
        onfocus=\"HideContent('btn');\" 
        name=\"username\" 
        type=\"text\" 
        id=\"username\" 
        value=\"{$user}\" />";

?>

Re: Can't get this code right

Posted: Thu Oct 06, 2011 9:33 am
by egg82

Code: Select all

echo '<input class="x"  
         onfocus="HideContent(\'btn\');" 
         name="username" 
         type="text" 
         id="username" 
         value="{$user}" />';
Keep it simple :P

Re: Can't get this code right

Posted: Thu Oct 06, 2011 9:44 am
by Celauran
egg82 wrote:

Code: Select all

echo '<input class="x"  
         onfocus="HideContent(\'btn\');" 
         name="username" 
         type="text" 
         id="username" 
         value="{$user}" />';
Keep it simple :P
Except your code doesn't work. Can't evaluate variables inside single quotes.

Code: Select all

echo '<input class="x"  
         onfocus="HideContent(\'btn\');" 
         name="username" 
         type="text" 
         id="username" 
         value="' . $user . '" />';

Re: Can't get this code right

Posted: Thu Oct 06, 2011 7:49 pm
by egg82
whoops, my bad! Thanks