SitePoint Sponsor

User Tag List

Results 1 to 17 of 17
  1. #1
    SitePoint Addict Bloodfest's Avatar
    Join Date
    Feb 2006
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    this.type Problems???

    I'm not very good at Javascript, so can anyone add in changing type to password:

    onfocus="if (this.value == Password) {this.value = '';}"

    I want the field to say Password the when the user clicks on it the type will be password type and the user can the enter there password.

  2. #2
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this (untested):
    Code:
    onfocus="if (this.value == 'Password') {this.value = '';}"

  3. #3
    SitePoint Addict Bloodfest's Avatar
    Join Date
    Feb 2006
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i'm sorry, maybe I wasn't clear on what I'm trying to do. You types the same code I already have.. I got it to Display "Password".. So the input type must be text.. Now when the user clicks on the textbox "Password" will disappear. This part I working, but I want to change the input type to password so when the user types in their passwaord, it will display the astriks.

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    onclick="document.getElementById('bla').type='password'"
    cheers

  5. #5
    SitePoint Addict Bloodfest's Avatar
    Join Date
    Feb 2006
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well it didn't work.. I replaced the bla with the field name "password"

    but nothing happens..

    This site has it, but I can't style the textbox..
    http://www.dynamicsitesolutions.com/...ng_input_type/

  6. #6
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok...
    use this code...
    Code:
    <input type="text" value="password" onclick="this.type='password'">
    cheers

  7. #7
    SitePoint Addict Bloodfest's Avatar
    Join Date
    Feb 2006
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's still not working.. Have you tried that code..?

  8. #8
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <input type="text" value="password" onclick="this.value='';this.type='password'">
    yes i tried it..
    cheers

  9. #9
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The type attribute of an input element is read-only in most browsers. You can't change it with a javascript assignment.

    You can rewrite the innerHTML, or use dom methods to replace the
    element with a password input.

    You could replace the text with asterisks on keydown, saving the
    actual text in a hidden element and passing the hidden value instead of the
    text box value on submit.
    Last edited by mrhoo; Oct 6, 2006 at 08:28. Reason: clarification

  10. #10
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mrhoo
    The type attribute of an input element is read-only. You can't change it with a javascript assignment.

    You could replace the text with asterisks on keydown, saving the
    actual text in a hidden element and passing the hidden value instead of the
    text box value on submit.
    what are u talking about ????
    lol

  11. #11
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What? You want a password box?
    <input type="password" name="myPassword" />

  12. #12
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    he want to see into the text input the value password and when someone click the value become empty and then when starts to type in the input type text become a input type password...
    the code ive wrote before works perfectly as he bring the link where is the example...
    cheers

  13. #13
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK I clicked the link and read the page. Someone tell me what is the point please, I'm totally missing it.

  14. #14
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    he want the same stuff with the inputs at the pahge that u visited...

  15. #15
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <never mind>
    Last edited by jimfraser; Oct 6, 2006 at 08:18. Reason: I get it

  16. #16
    SitePoint Addict Bloodfest's Avatar
    Join Date
    Feb 2006
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, here's the problem... I tried it in FF and it's works perfectly.. IE7 it does not work.. Thats the delima..

  17. #17
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,834
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    The following should work for all modern browsers.

    HTML

    Code:
    <input type="text" value="Password" onfocus="chg();" id="d1">
    <input type="password" id="d2" style="display:none">
    Javascript

    Code:
    function chg() {
    document.getElementById('d1').display = 'none';
    document.getElementById('d2').display = 'block';
    }
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


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
  •