Jump to content

Kingdom

Members
  • Content count

    3
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Kingdom

  • Rank
    Newbie
  • Birthday 10/18/1987

Profile Information

  • Location
    Brazil, Santa Catarina

Previous Fields

  • Languages
    English, Portuguese, Spanish
  1. Kingdom

    Checking If Input Is Empty After User Editing

    Yep, that fixed it... Swapped .setAttribute("value","password") for .value... Thanks! Solved!
  2. Kingdom

    Checking If Input Is Empty After User Editing

    Thanks, that's was just a typo on paste. Fixed! The value returned is indeed what i expect, empty, as i said on the first post. I've added an alert to detect if the script was being triggered, and it is, but the value of the input won't be updated after editing... Here's the new code with detect: function loginFormToggleFillers(element){ var loginF = document.loginForm.login; var user = loginF.value; var passwordF = document.loginForm.password; var password = passwordF.value; if(element){ el = element.attributes["name"].value; if( el == "login" ){ if ( user == "" || user.length == 0 ){ alert("detected"); loginF.setAttribute("value", "user@mail.com"); } if ( user == "user@mail.com" ){ loginF.setAttribute("value", ""); } } else if ( el == "password" ){ if ( password == "" || password.length == 0 ){ alert("detected"); passwordF.setAttribute("value", "password"); } if ( password == "password" ){ passwordF.setAttribute("value", ""); } } } else { if ( user == "" || user.length == 0 ){ alert("detected"); loginF.setAttribute("value","user@mail.com"); } if ( password == "" || password.length == 0 ){ passwordF.setAttribute("value","password"); } }}loginFormToggleFillers(null); Any other ideas?
  3. The idea:The idea is to automatically fill the fields with "user@mail.com" and "password" if they're left blank. The problem:Well, the Javascript check is working and doing what it is supposed to. However, if the user adds a value, and then erases that value leaving the input empty, the script doesn't detects the field as empty... although the value returned is indeed empty like "". The code: function loginFormToggleFillers(element){ var loginF = document.loginForm.login; var user = loginF.value; var passwordF = document.loginForm.password; var password = passwordF.value; if(element){ el = element.attributes["name"].value; if( el == "login" ){ if ( user == "" || user.length == 0 ){ loginF.setAttribute("value", "user@mail.com"); } if ( user == "user@mail.com" ){ loginF.setAttribute("value", ""); } } else if ( el == "password" ){ if ( password == "" || password.length == 0 ){ passwordF.setAttribute("value", "password"); } if ( password == "password" ){ passwordF.setAttribute("value", ""); } } } else { if ( user == "" || user.length == 0){ loginF.setAttribute("value","user@mail.com"); } if ( password == "" || password.length == 0){ passwordF.setAttribute("value","password"); } }}loginFormToggleFillers(null); The HTML call (wrote by hand, so there might be a mistake somewhere... but it's just the idea): <input type="text" name="login" onFocus="loginFormToggleFillers(this)" onBlur="loginFormToggleFillers(this)" /><input type="password" name="password" onFocus="loginFormToggleFillers(this)" onBlur="loginFormToggleFillers(this)"/> Any ideas on this? Thanks in advance!
×