Dicko_md Posted June 26, 2013 Share Posted June 26, 2013 This is my current code but if I try and swap the code function FormLogin() { $html = " <div id='login'> <form method='post' name='forml' action='index_1.php?s=login'> <input type='hidden' name='dologin' value='1'> <table cellpadding='2'> <tr><td class='formlabel'>Email:</td><td><input type='text' name='email' value='EMAIL' style='width: 100%'></td></tr> <tr><td class='formlabel'>Password:</td><td><input type='password' name='password' style='width: 100%'></td></tr> <tr><td> </td><td><input type='submit' class='submit' name='login' value='SIGN IN' id='submit' style='width: 100%'></td></tr> <tr><td> </td><td><p align='center'><a class='dark' href='index.php?s=remindpass'>FORGOT PASSWORD</a></p></td></tr> </table> <br /></div> <script language='javascript'> document.forml.email.focus(); </script> </form> "; return $html; } with the below it doesn't work. I have tried swapping the " with ' and that didn't work. Have I missed something as the below code works in a normal php file . <form method='post' name='forml' action='index_1.php?s=login'> <input type='hidden' name='dologin' value='1'> <input type="text" name="email" value="email" onfocus="if (this.value=='email') this.value='';"/> <input type="password" name="password" value="password" onfocus="if (this.value=='password') this.value='';"/> <input type="submit" name="login" id="submit" value="SIGN IN" class="submit"> <a class="dark" href='index_1.php?s=remindpass'>FORGOT PASSWORD</a> </form> Thanks in advance Martyn Quote Link to comment Share on other sites More sharing options...
dalecosp Posted June 26, 2013 Share Posted June 26, 2013 Are you trying to debug the onfocus() in the Javascript?Have you tried Firebug or Chrome debugger? Quote Link to comment Share on other sites More sharing options...
Dicko_md Posted June 26, 2013 Author Share Posted June 26, 2013 Hi Im still learning and no I haven't. How would I do that ? I know it works in a normal php file but I was wondering if its the " around the onfocus as the other items can have ' instead Thanks Quote Link to comment Share on other sites More sharing options...
Dicko_md Posted June 26, 2013 Author Share Posted June 26, 2013 <form method='post' name='forml' action='index_1.php?s=login'> <input type='hidden' name='dologin' value='1'> <input type='text' name='email' value='email' onfocus="if (this.value=='email') this.value='';"/> <input type='password' name='password' value='password' onfocus="if (this.value=='password') this.value='';"/> <input type='submit' name='login' id='submit' value='SIGN IN' class='submit'> <a class="dark" href='index_1.php?s=remindpass'>FORGOT PASSWORD</a> </form> Ive just tried this in the normal php file and it works fine. When I tried taking off the " off the onfocus to ' it left the EMAIL and ****** in the boxes. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 26, 2013 Share Posted June 26, 2013 I took your code and ran it and it worked just fine. When I tabbed into the email field the prompt went away. although I did add an onload to the body tag to get the focus to happen automatically (and some ids). Show us what your "swapped" version looks like. Quote Link to comment Share on other sites More sharing options...
Dicko_md Posted June 26, 2013 Author Share Posted June 26, 2013 This is what I tried. function FormLogin() { $html = " <form method='post' name='forml' action='index_1.php?s=login'> <input type='hidden' name='dologin' value='1'> <input type='text' name='email' value='email' onfocus="if (this.value=='email') this.value='';"/> <input type='password' name='password' value='password' onfocus="if (this.value=='password') this.value='';"/> <input type='submit' name='login' id='submit' value='SIGN IN' class='submit'> <a class="dark" href='index_1.php?s=remindpass'>FORGOT PASSWORD</a> <script language='javascript'> document.forml.email.focus(); </script> </form> "; return $html; } Ive tried with and without the script. Im guessing it is something with the " on the onfocus as its closing the line. Ive also tried \" also Thanks Martyn Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 26, 2013 Share Posted June 26, 2013 Yes - you will need to escape that double quote for the onfocus part. So - what isn't working? Are you getting the $html var set with the content of the form? Have you echoed it to see what it looks like? If you are getting the content, what are you doing with it next? What isn't working??? Quote Link to comment Share on other sites More sharing options...
dalecosp Posted June 26, 2013 Share Posted June 26, 2013 Hi Im still learning and no I haven't. How would I do that ? I know it works in a normal php file but I was wondering if its the " around the onfocus as the other items can have ' instead Thanks Use Chrome, or install the Firebug extension in your Firefox browser. Then read this. Quote Link to comment Share on other sites More sharing options...
Dicko_md Posted June 26, 2013 Author Share Posted June 26, 2013 I have changed he " to ' onfocus but that hasn't changed anything. I get nothing output. The webpage is just white. Not sure how to debug Thanks Quote Link to comment Share on other sites More sharing options...
Dicko_md Posted June 26, 2013 Author Share Posted June 26, 2013 Thanks reading now but if anyone knows why its doing it. please tell. thanks again Quote Link to comment Share on other sites More sharing options...
Dicko_md Posted June 26, 2013 Author Share Posted June 26, 2013 Nothing is been output. just says below and no arrows next to them with any code in <head></head> <body></body> Thanks Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 26, 2013 Share Posted June 26, 2013 you need to escape the double quotes on the onfocus= because it is competing with the starting " for the whole string. LIke this: onfocus=\"if (this.value=='password') this.value='';\"/> You're only getting the default html and body tags because your $html var is not valid because of the quote marks confusion. Quote Link to comment Share on other sites More sharing options...
Dicko_md Posted June 26, 2013 Author Share Posted June 26, 2013 Hi That didn't work. I got the same. Thanks again Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 26, 2013 Share Posted June 26, 2013 PLEASE post the code so you can be helped. Quote Link to comment Share on other sites More sharing options...
Dicko_md Posted June 26, 2013 Author Share Posted June 26, 2013 <a class="dark" href='index_1.php?s=remindpass'>FORGOT PASSWORD</a> This is the offending line. I removed it and it worked fine. Does anything stand out ? Quote Link to comment Share on other sites More sharing options...
Solution zmasta101 Posted June 26, 2013 Solution Share Posted June 26, 2013 <?php function FormLogin() { $html = " <form method='post' name='forml' action='index_1.php?s=login'> <input type='hidden' name='dologin' value='1'> <input type='text' name='email' value='email' onfocus=\"if (this.value=='email') this.value='';\"/> <input type='password' name='password' value='password' onfocus=\"if (this.value=='password') this.value='';\"/> <input type='submit' name='login' id='submit' value='SIGN IN' class='submit'> <a class='dark' href='index_1.php?s=remindpass'>FORGOT PASSWORD</a> <script language='javascript'> document.forml.email.focus(); </script> </form> "; return $html; } echo FormLogin(); ?> The above example works. Since you are only returning $html in the function, make sure you are using either print or echo so it will output to the screen Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 26, 2013 Share Posted June 26, 2013 You don't understand the usage of quotes and double quotes. If you begin a string with one type of quote (single or double) you can't use that same kind of quote again in the string without escaping it (preceding it with a \). Should you need to quote something always use the other type of quote to do so. So, in your case, when you start a string with a double quote ($html = "....), you have to use single quotes to encase any other strings inside meaning that the parms of your <a> tag are quoted incorrectly. IMHO it is preferable to always use double quotes on strings since any php var used inside will then be evaluated without having to break the string up. Anything inside the string requiring quotes can always use the single quote, again avoiding having to use escape sequences. $var = "<input type='text' name='name' value='$myvar'>"; will always work while $var = '<input type="text" name="name" value="$myvar">'; will not do what you want since the outer quotes were single and thus the php var will show up literally as '$myvar'. Quote Link to comment Share on other sites More sharing options...
Dicko_md Posted June 27, 2013 Author Share Posted June 27, 2013 Thank you all for your help. Im definately learning slowly. Martyn Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.