Jump to content

[SOLVED] Alternating values in input boxes


rv20

Recommended Posts

I have a login form with 2 input text boxes and their values are set to username and password initally so if a user clicks on one i want clear that input box and if no value is entered in theother input box then make sure that that other input boxes value is either username or password, here is what i have so far, it half works although if you actually type in a username or password and click the other box then it is cleared which i don't want,

 

<form action ="post" method ="?login" >

<input type = "text" value = "username" id ="u1" 

onfocus="this.value='';document.getElementById('p1').value='password'" >
<input type = "text" value = "password" id ="p1" 

onfocus="this.value='';document.getElementById('u1').value='username'">

</form>

 

 

So like say if "the other box" doesn't have a password or username entered then then make it's value back to username or password.

<form action ="post" method ="?login" >
<input type = "text" value = "username" id ="u1" onfocus="this.value='';" onblur="this.value=this.value===''? 'username':this.value;">
<input type = "text" value = "password" id ="p1" onfocus="this.value='';" onblur="this.value=this.value===''? 'password':this.value;">
</form>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.