Reaper0167 Posted June 10, 2009 Share Posted June 10, 2009 I am having a problem with a text box on my site. The text box is where I enter in a password,, so when I type something,,, it is just a bunch of black dots.... How would I go about having the initial value of that text box say 'Password' .. When I set the initial value to password,, it shows black dots,, only cause the type of the box is set to password.... What is the way around this? Quote Link to comment Share on other sites More sharing options...
J.Daniels Posted June 10, 2009 Share Posted June 10, 2009 The only way around this is to use JavaScript to change the type of the input Quote Link to comment Share on other sites More sharing options...
Andy-H Posted June 10, 2009 Share Posted June 10, 2009 <head> <script type="text/javascript"> <!-- function changeType() { document.getElementById('password').type = 'text'; } --> </script> </head> <body onload="changeType()"> <input name="password" type="password" value="Password" id="password" onfocus="if (this.value == 'Password' && this.type == 'text'){ this.value = ''; this.type = 'password'; this.focus(); }" onblur="if (this.value == '' && this.type == 'password'){ this.value = 'Password'; this.type = 'text'; }" > </body> Quote Link to comment Share on other sites More sharing options...
haku Posted June 11, 2009 Share Posted June 11, 2009 Be warned that if the user doesn't have javascript turned on, the password field will then never exist, and they will be typing their password into a text field. If I found that on a site, I wouldn't sign up - I'm sure I'm not the only one. Quote Link to comment Share on other sites More sharing options...
Andy-H Posted June 11, 2009 Share Posted June 11, 2009 Not in the code I supplied as the default type of the input is password and is changed by the changeType() (javascript) function onload of the document body, so if js is disabled the input box will still be password type and have a value of password which needs to be deleted manually. Quote Link to comment Share on other sites More sharing options...
Reaper0167 Posted June 11, 2009 Author Share Posted June 11, 2009 I forgot to mention that I am echoing out the form..... I'm getting an error.... <?php echo '<form name="form1" method="post" action="login.php"> <body onload="changeType()"> <input name="password" type="password" value="Password" id="password" onfocus="if (this.value == "Password" && this.type == "text"){ this.value = ''; this.type = "password"; this.focus(); }" onblur="if (this.value == '' && this.type == "password"){ this.value = "Password"; this.type = "text"; }" > <input name="password" type="password" id="password" /> <input type="submit" name="submit" id="submit" value="Login"><br> </form>'; ?> Quote Link to comment Share on other sites More sharing options...
haku Posted June 11, 2009 Share Posted June 11, 2009 Why are you echoing it out? There is no need. Just exit php before the form, and enter it after the form (if necessary). Quote Link to comment Share on other sites More sharing options...
Reaper0167 Posted June 11, 2009 Author Share Posted June 11, 2009 I'm using an if statement,,, if no one is logged in,, echo the form,,, else echo welcome message. Quote Link to comment Share on other sites More sharing options...
Andy-H Posted June 11, 2009 Share Posted June 11, 2009 <head> <script type="text/javascript"> <!-- function changeType() { document.getElementById('password').type = 'text'; } //The javascript function needs to be in the head of the document as shown. --> </script> </head> <body onload="changeType()"> <!-- ^^^This needs to be the actual body tag of the document --> <?php echo '<form name="form1" method="post" action="login.php"> <input name="password" type="password" value="Password" id="password" onfocus="if (this.value == 'Password' && this.type == 'text'){ this.value = ''; this.type = "password"; this.focus(); }" onblur="if (this.value == '' && this.type == 'password'){ this.value = 'Password'; this.type = 'text'; }" /> <input type="submit" name="submit" id="submit" value="Login"><br> </form>'; ?> And the ' need to be escaped with a backslash, will work if you use it as previously stated. BTW, you can still jump out of PHP and display the code as needed like so: <?php if ( isSet($_SESSION['userName']) ) { ?> <form name="form1" method="post" action="login.php"> <input name="password" type="password" value="Password" id="password" onfocus="if (this.value == 'Password' && this.type == 'text'){ this.value = ''; this.type = "password"; this.focus(); }" onblur="if (this.value == '' && this.type == 'password'){ this.value = 'Password'; this.type = 'text'; }" /> <input type="submit" name="submit" id="submit" value="Login"><br> </form> <?php } else { echo $welcomeMsg; } ?> Quote Link to comment Share on other sites More sharing options...
haku Posted June 11, 2009 Share Posted June 11, 2009 <?php if(no one logged in) { ?> <form> form stuff </form> <?php } else { other stuff } Quote Link to comment Share on other sites More sharing options...
Reaper0167 Posted June 11, 2009 Author Share Posted June 11, 2009 haku,,, is that right what you posted,, never seen anything like that before.... I mean the way the curly brackets are place in and out of the php tags. Quote Link to comment Share on other sites More sharing options...
haku Posted June 11, 2009 Share Posted June 11, 2009 I wouldn't have posted it otherwise. Quote Link to comment Share on other sites More sharing options...
Andy-H Posted June 11, 2009 Share Posted June 11, 2009 haku,,, is that right what you posted,, never seen anything like that before.... I mean the way the curly brackets are place in and out of the php tags. lol, the braces are posted inside the PHP tags, PHP is parsed before the content is displayed. Kind of like the define function searches for the defined constant and replaces each occurance with the the corresponding value. If the statement evaluates to false, the code within the braces will not be sent to the browser. Yes, its right Quote Link to comment Share on other sites More sharing options...
Reaper0167 Posted June 11, 2009 Author Share Posted June 11, 2009 hey,, thanks guys. I just have one more post in the javascript section, if one of you have some time,, i would really appreciate it Quote Link to comment Share on other sites More sharing options...
Andy-H Posted June 11, 2009 Share Posted June 11, 2009 <head> <script type="text/javascript"> <!-- function changeType() { document.getElementById('password').type = 'text'; } //The javascript function needs to be in the head of the document as shown. --> </script> </head> <body onload="changeType()"> <!-- ^^^This needs to be the actual body tag of the document --> Please be sure to implement this part otherwise, the javascript in the input will not work as he type will be set to password, also, dont just change the default type of input to text or else as haku previously stated the passwords will be displayed as clear text if javascript is disabled. Quote Link to comment Share on other sites More sharing options...
Reaper0167 Posted June 11, 2009 Author Share Posted June 11, 2009 Thanks for the info. In the javascript section,,, still having trouble with the checkbox validation... If you have time,, I would greatly appreciate it. 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.