Jump to content

Form Input Script Not Working.


Yvil

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

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.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...