0

i want to do so then a person click on the input box it should hide the standard "custom" text

i have this

echo form_input('username', 'Username', 'class="login_input"');

how can i do with javascript that username get remove then clicked?

Thanks

3 Answers 3

3

This way, both onfocus and onblur event will work

//script tag starts
function myFocus(element) {
     if (element.value == element.defaultValue) {
       element.value = '';
     }
   }
   function myBlur(element) {
     if (element.value == '') {
       element.value = element.defaultValue;
     }
   }
//script tag ends


echo form_input('username', 'Username', 'class="login_input" onfocus="myFocus(this);" onblur="myBlur(this);" ');
Sign up to request clarification or add additional context in comments.

Comments

1

Try:

echo form_input('username', 'Username', 'class="login_input" onfocus="this.value=\'\'"');

1 Comment

the problem is that if he type something and then click it, its gone
0

Try this

echo form_input('username', 'Username', 'class="login_input" onblur="if (this.value == \'\') {this.value = \'Custom\';}"  onfocus="if (this.value == \'Custom\') {this.value = \'\';}" value="Custom"');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.