Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    May 2004
    Location
    Some place called the Earth I think...
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts

    HELP concerning javascript input values

    First, id like 2 say hello because i am new here and dont think im dumb, because im 13 years old and know Css, Html, and learning Javascript...

    Ok, now 2 my question. Is there any way to have the default value of a text box be in text, but then when u focus on it, it will change to the dots for a password? look at my code so far:

    http://www.freewebs.com/death_by_mon...low%20test.htm

    o and the music on there isnt mine but im not going to use it for anything, just to see how the code worked with music. All the other codes on that page are just some codes ive been working on
    Last edited by DooM_MonkeY; 05-28-2004 at 12:30 AM.

  • #2
    New Coder
    Join Date
    May 2004
    Location
    Some place called the Earth I think...
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts
    o and i already tryed

    function type_change() {

    document.all.box2.type="password";
    }

    but it didnt work so any suggestions?┐?

  • #3
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    hmm. . .

    you might try:

    Code:
    <html>
    <head>
    <script type="text/javascript">
    
    function changeInput()
    {
    document.getElementById('passSpot').innerHTML='<input type="password" id="pass">';
    document.getElementById('pass').focus();
    }
    </script>
    </head>
    <body>
    <form>
    <div id='passSpot'>
    <input type="text" value="Enter Password" onfocus="changeInput()">
    </div>
    </form>
    </body>
    </html>
    Doesn't seem to want to focus on the password field after the switch, not sure why.

    Basscyst
    Last edited by Basscyst; 05-28-2004 at 12:55 AM.
    Helping to build a bigger box. - Adam Matthews

  • #4
    New Coder
    Join Date
    May 2004
    Location
    Some place called the Earth I think...
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts
    omg it worked!! wow, it was that easy, i never thought of an innerHTML for that. thank you, ive been needing 2 crack the math on that for a while, lemme see how it works with my other scripts

    hmmmm, wonder y it isnt focusing
    Last edited by DooM_MonkeY; 05-28-2004 at 01:15 AM.

  • #5
    New Coder
    Join Date
    May 2004
    Location
    Some place called the Earth I think...
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts
    wait, how would i put the onmouseover="" type stuff in that? in innerHTML the javascripts never work for me. Is it because the ' tags can't be used inside each other? how would i change the ' tags so the scripts inside of the innerHTML still work?

    (like i might have said, still new to Javascript)
    Last edited by DooM_MonkeY; 05-28-2004 at 01:17 AM.

  • #6
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    I think you are wondering how you would pass a variable to the function:

    Seperate the string (the html) from a variable with the plus sign. Make sure you close the string with a quote. You can use either or but not both. If you start a string with a single quote you must close the string with a single quote. Allowing you to use the double quote for the HTML.

    somthing like:

    Code:
    <html>
    <head>
    <script type="text/javascript">
    var str='mommy';
    function doAlert(x)
    {
    alert(x);
    }
    
    function changeInput()
    {
    document.getElementById('passSpot').innerHTML='<input type="password" id="pass"><input type="button" onclick=doAlert("'+str+'")>';
    document.getElementById('pass').focus();
    }
    </script>
    </head>
    <body>
    <form>
    <div id='passSpot'>
    <input type="text" value="Enter Password" onfocus="changeInput()">
    </div>
    </form>
    </body>
    </html>
    Helping to build a bigger box. - Adam Matthews

  • #7
    New Coder
    Join Date
    May 2004
    Location
    Some place called the Earth I think...
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yes thank you, i still havent figured out the focus problem yet but im working on it with this: http://www.freewebs.com/death_by_mon...rd_testing.htm

    you have to click the reset button (fake reset button) twice until the 'password' value comes back tho

    with the colors i was just trying to see if a style could be applied to it (dont no y it wouldnt but hey)
    Last edited by DooM_MonkeY; 05-28-2004 at 02:51 AM.

  • #8
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try this:
    Code:
    <script type="text/javascript">
     <!--//
      function changeType(input){
        if(input.type == 'text'){
           password = document.createElement('input');
           password.name = 'password'
           password.type = 'password';
           input.parentNode.insertBefore(password,input);
           input.parentNode.removeChild(input);
           password.value = '';
           password.focus();
        }
      }
     //-->
    </script>
    </head>
    
    <body>
    <form method="get" action="">
    Password:<input type="text" value="Please Enter a Password"
    name="password" onfocus="changeType(this)">
    </form>

  • #9
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    BTW: Below is an example of adding an event handler to call a javascript function. (I changed the alert to innerHTML because the alert would kill the focus demonstration)

    Code:
    <script type="text/javascript">
     <!--//
      var str='mommy';
      function doAlert(x){
        document.getElementById('test').innerHTML = x;
      }
    
    
      function changeType(input){
        if(input.type == 'text'){
           password = document.createElement('input');
           password.name = 'password'
           password.type = 'password';
           password['onclick'] = new Function(doAlert(str));
           input.parentNode.insertBefore(password,input);
           input.parentNode.removeChild(input);
           password.value = '';
           password.focus();
        }
      }
     //-->
    </script>
    </head>
    
    <body>
    <form method="get" action="">
    Password:<input type="text" value="Please Enter a Password"
    name="password" onfocus="changeType(this)">
    </form>
    <span id="test"></span>

  • #10
    New Coder
    Join Date
    May 2004
    Location
    Some place called the Earth I think...
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hehey that workd too, thanks alot guys uve really helped
    Dont do drugs, get high on life

    13 years and getting nowhere fast.....


    đ­˘M_M÷˝kŔą


  •  

    Posting Permissions

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