Jump to content

[SOLVED] password text boxes and initial values


Reaper0167

Recommended Posts

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?

Link to comment
Share on other sites


<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>

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>';
?>

Link to comment
Share on other sites

<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;
}
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites


<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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.