$(document).ready(function() {
// #login-box password field
$('#password').attr('type', 'text');
$('#password').val('Password');
});
This is supposed to change the #password
input field (with id="password"
) that is of type
password
to a normal text field, and then fill in the text “Password”.
It doesn’t work, though. Why?
Here is the form:
<form enctype="application/x-www-form-urlencoded" method="post" action="/auth/sign-in">
<ol>
<li>
<div class="element">
<input type="text" name="username" id="username" value="Prihlasovacie meno" class="input-text" />
</div>
</li>
<li>
<div class="element">
<input type="password" name="password" id="password" value="" class="input-text" />
</div>
</li>
<li class="button">
<div class="button">
<input type="submit" name="sign_in" id="sign_in" value="Prihlásiť" class="input-submit" />
</div>
</li>
</ol>
</form>
Have you tried using .prop()?
http://api.jquery.com/prop/
Type properties can't be changed you need to replace or overlay the input with a text input and send the value to the password input on submit.
I received the same error message while attempting to do this in Firefox 5.
I solved it using the code below:
And to use it, just set the onFocus and onBlur attributes of your fields to something like the following:
I use this for a username field as well, so it toggles a default value. Just set the second parameter of the function to '' when you call it.
Also it might be worth noting that the default type of my password field is actually password, just in case a user doesn't have javascript enabled or if something goes wrong, that way their password is still protected.
The $(document).ready function is jQuery, and loads when the document has finished loading. This then changes the password field to a text field. Obviously you'll have to change 'password_field_id' to your password field's id.
Feel free to use and modify the code!
Hope this helps everyone who had the same problem I did :)
-- CJ Kent
EDIT: Good solution but not absolute. Works on on FF8 and IE8 BUT not fully on Chrome(16.0.912.75 ver). Chrome does not display the Password text when the page loads. Also - FF will display your password when autofill is switched on.
I like this way, to change the type of an input element: old_input.clone().... Here is an example. There is an check box "id_select_multiple". If this is is changed to "selected", input elements with name "foo" should be changed to check boxes. If it gets unchecked, they should be become radio buttons again.
Just another option for all the IE8 lovers, and it works perfect in newer browsers. You can just color the text to match the background of the input. If you have a single field, this will change the color to black when you click/focus on the field. I would not use this on a public site since it would 'confuse' most people, but I am using it in an ADMIN section where only one person has access to the users passwords.
-OR-
This, also needed, will change the text back to white when you leave the field. Simple, simple, simple.
[ Another Option ] Now, if you have several fields that you are checking for, all with the same ID, as I am using it for, add a class of 'pass' to the fields you want to hide the text in. Set the password fields type to 'text'. This way, only the fields with a class of 'pass' will be changed.
Here is the second part of this. This changes the text back to white after you leave the field.