Jump to content

Form Input Script Not Working.


Yvil
 Share

Recommended Posts

Hey everybody,I've got this form input script that (should) change the input value to 'username' when the value is nothing:

<form><input type="text" name="un" value="username" onblur="if (this.value = '', this.value = 'username');" onfocus="if (this.value = 'username', this.value = '');" /></form>

It all works for the "onfocus" part, but the "onblur" part doesn't work: it automaticly changes the value to 'username', no matter what the current value is.Does anyone know why this could be?Thanks in advance,Yvil

Edited by Yvil
Link to comment
Share on other sites

Your statements don't do what you think they do.1. In the conditional part of your if statement, you need the comparison operator ( == ) not the assignment operator ( = ).2. Use the correct syntax for the if statement:

if (this.value == '') {this.value = 'username';}

Notice where I closed the parentheses and where I put the braces. Notice that there is no comma. The comma is a real operator, but it is not used in simple if statements.You'll need to correct the onfocus part also. If it seems to work now, it can only be because you haven't tested it thoroughly.

Edited by Deirdre's Dad
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...