SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Changing Input Type

    I'm trying to change an input type onevent, but not having any luck. Is it possible?

    Is can get the type by using
    Code:
    <p>
    <input id="password" name="Password" type="text" value="Password" onclick="alert(this.type)"></input>
    </p>
    but I can't seem to change the type from here.
    As an alternative I was thinking of using
    Code:
    <p>
    <input id="password" name="Password" type="text" value="Password" onclick="this.parentElement.innerHTML='<input type=password value=password></input>'"></input>
    </p>
    Any suggestions? It's only so I can have "password" written in the input, which changes to &bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;
    when clicked.
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  2. #2
    SitePoint Addict
    Join Date
    Mar 2003
    Location
    CA
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <input type="password" id="p" name="p" value="" onclick="this.type = 'text';" onblur="this.type='password';"/>
    seems to work in firebird. Another way would be on the onblur event to store the user's input into a textfield in a jscript variable and replace the text in the form with bullets. When the user clicks on the textfield you would replace the bullets with the contents of the variable. Make sure on the onsubmit event you place the value of the jscript variable into a hidden field and that the submit method is post.
    -ChaCha

  3. #3
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks ChaCha. With IE I get
    could not get the type property. This command is not supported
    Cheers for the other idea, more old browser compliant than changing innerHTML

    The this.type= works in Opera and NS too, Think I'll use that as default, with if(ie) changeinnerHTML()
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  4. #4
    SitePoint Addict
    Join Date
    Mar 2003
    Location
    CA
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This works fine...

    Code:
    <form name="f" id="f">
    <input type="text" id="t" name="t" value="" onfocus="this.value = this.form.h.value;" onblur="this.form.h.value=this.value; this.value='********';"/>
    <input type="hidden" name="h" id="h" value="" />
    </form>
    -ChaCha

  5. #5
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dug this out of the archives...
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" 
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    <head>
    <title>untitled</title>
    <script type="text/javascript" language="javascript">
    
    function toPassword(oInput) {
    	var newEl = document.createElement('input');
    	newEl.setAttribute('type', 'password');
            newEl.setAttribute('name', 'password');
    	oInput.parentNode.replaceChild(newEl,oInput);
    	toPassword.el = newEl;
    	setTimeout('toPassword.el.focus()',100);
    	return true;
    }
    
    </script>
    </head>
    <body>
    <input type="text" name="username" value="Enter your Username" 
    onfocus="if(this.value==this.defaultValue)this.value=''">
    <input type="text" name="password" value="Enter your Password" 
    onfocus="if(this.value==this.defaultValue)return toPassword(this)">
    </body>
    </html>
    ::: certified wild guess :::

  6. #6
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ::: certified wild guess :::

  7. #7
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Cheers Adios.....works on all........
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if


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
  •