Istiak Mahmood
Istiak Mahmood

Reputation: 2422

required is not working for the text field

required is working only for the if statment, although I have finished the endif, but at the same time I am not sure that this is how it should be done the endif.

Now the required is working only for the if stament not for the whole text field, how it can work both for if-else statement and also for the whole text field.

Does someone know how to solve this problem.

 <input  type="text" name="name" value="search name" onfocus="if (this.value == 'search name') {this.value = '';} endif;" required> 

If I just write like so for text field, it works perfectly:

<input  type="text" name="name" required>

But I need to add a value before it click the text field, that's why I added:

value="search name" onfocus="if (this.value == 'search name') {this.value = '';} endif;"

Can someone knows how to fix this problem!

Upvotes: 2

Views: 104

Answers (2)

DirtyBit
DirtyBit

Reputation: 16772

Try adding placeholder attribute:

<input  type="text" name="name" placeholder = "search name" required>

Upvotes: 2

aldrin27
aldrin27

Reputation: 3407

Try this:

  <input type="text" name="name" onclick="(this.value != null) ? this.value : ' ' " required placeholder="search here" />

Upvotes: 2

Related Questions