We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,289 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

change input type in js

iam doing it so that it inside input field it should say "Password". then if user start type in than it should put chars ****.

 html file
 <input type="password" name="password" id="login_password" class="login_field" value=""/>

 js file
 /*** login page - password field ***/  


var password = 'Password';
$('#login_password').replaceWith('<input type="text" value="" name="password" id="login_password" class="login_field">');
$('#login_password').css('color', 'gray');
$('#login_password').attr('value', password).focusin(function()
{   

    $(this).css('color', 'black');
    if($(this).val() == password)
    {
        $(this).replaceWith('<input type="password" value="" name="password" id="login_password" class="login_field">');
        $('#login_password').fousin();
    }
}).focusout(function()
{
    if($(this).val() == '')
    {
        $(this).attr('value', password);
    }
});

not sure if this is the right way to do this task. there is also a small bug. when i foucs on input filed i have to click two times.

2
Contributors
2
Replies
2 Hours
Discussion Span
6 Months Ago
Last Updated
3
Views
Question
Answered
hwoarang69
Posting Pro
569 posts since Feb 2012
Reputation Points: 6
Solved Threads: 0
Skill Endorsements: 7

If you do a search for "input password watermark", you'll find plenty of examples on this topic. The challange here is to have plain text in place, then when you focus in on the input element, switch over to having the input element with a type of "password" instead of type of "text".

Here is a jsfiddle example i came across.
http://jsfiddle.net/jquerybyexample/TwTt9/

JorgeM
Industrious Poster
4,023 posts since Dec 2011
Reputation Points: 297
Solved Threads: 548
Skill Endorsements: 115

thanks. that example was perfect for what i was doing.

hwoarang69
Posting Pro
569 posts since Feb 2012
Reputation Points: 6
Solved Threads: 0
Skill Endorsements: 7
Question Answered as of 6 Months Ago by JorgeM

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0747 seconds using 2.69MB