Results 1 to 1 of 1

Thread: control input fields 'type' attribute jQuery

  1. #1
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default control input fields 'type' attribute jQuery

    i have this jquery code that alters the input fields value.

    i would like to control its 'type' attribute.

    this kind of works but it feels off,
    is there a better way of handling this task?
    Code:
    	$('#password').live("click", function(){
    		if( $(this).val() == "Password" ) { 
    			$(this).val("").css({'color':'#000'});
    		}else{
    			$(this).css({'color':'#000'});
    		}
    		
    		var oldButton = $(this);
        var newButton = oldButton.clone();
    
        newButton.attr("type", "password");
        newButton.attr("id", "newPassword");
        newButton.insertBefore(oldButton);
        oldButton.remove();
        newButton.attr("id", "password");
    	});
    	
    	$("#password").blur(function() {
    
    		 if( $(this).val() == "" ) {
    		 
    		 
    			var oldButton = $(this);
    			var newButton = oldButton.clone();
    
    			newButton.attr("type", "text");
    			newButton.attr("id", "newPassword");
    			newButton.insertBefore(oldButton);
    			oldButton.remove();
    			newButton.attr("id", "password");
    			
    			$(this).val("Password").css({'color':'#777'});
    		} 
    	});

    RE: this did the trick
    Code:
    $(this).get(0).type = 'password';
    Last edited by ggalan; 05-22-2012 at 02:54 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •