tags:

views:

40

answers:

2

it is the problem, i can't undertand anyway. i have the following simple script


    <input class="input"  type="text" name="l_username" style="color: #ccc;" 
     value= " <?if ($_POST[l_username] != '') 
              echo $_POST[l_username];
              else echo 'something';?>"   
     onfocus="if (this.value == 'something') {
 this.value='';this.style.color='black';}" />

onfocus doesn't work here, but when i delete php script from value, it works


<input class="input"  type="text" name="l_username" style="color: #ccc;" 
         value= " something"   
         onfocus="if (this.value == 'something') {
     this.value='';this.style.color='black';}" />

it works fine. could you tell me why? thanks

+1  A: 
 " <?if ($_POST[l_username] != '') 
              echo $_POST[l_username];
              else echo 'something';?>" 

because of the space character before <?

In your focus event handler you could use the defaultValue property, so you don't have to repeat the "something" string twice

onfocus="if(this.value === this.defaultValue){this.value='';this.style.backgroundColor='black';}"
Rafael
@Rafael it's very useful, thanks
Syom
+1  A: 
<input class="input"  type="text" name="l_username" style="color: #ccc;" 
 value= " <?if ($_POST[l_username] != '') 
          echo $_POST[l_username];
          else echo 'something';?>"   
 onfocus="if (this.value == 'something') {
this.value='';this.style.color='black';}" />

you have a space in front of your PHP script. Try to remove it to match the javascript if case (if (this.value == 'something')

Mannaz
@Mannaz yes, you're true, thanks;)
Syom