0

I want these two effects to take place without using a function, is there any syntax ?

onkeypress="this.value=(this.value=='Password')?'' : this.value"

onkeypress="this.type='password'"

Aayush
  • 223
  • 1
  • 3
  • 13

2 Answers2

1

<input type="password" placeholder="Password"> will be better suited for what you are trying to do. However, to answer your question: Just put both statements in the same handler:

onkeypress="if (this.value=='Password') this.value = ''; this.type = 'password';"

Notice that you will get problems with Internet Explorer which does not allow changing the type of an input element. See also this answer.

Community
  • 1
  • 1
Bergi
  • 630,263
  • 148
  • 957
  • 1,375
0

Hey good question.

onclick="checkPassword();"

then have a JavaScript (with what Bergi mentioned):

var pw = document.getElementById("password");

if (pw.value=='Password') pw.value = ''; pw.type = 'password';

HTML:

<input type="password" id="password"/>
electrikmilk
  • 1,013
  • 1
  • 11
  • 23