Reputation: 3190
I have the following code:
<input type = "Text" value="" class="MyClass"/>
Can value be declared as empty?
In the chrome debugger, it appears like the following, which doesn't look correct
However the onkeypress event is never fired. I'm guessing it's because the "value" attribute looks a bit weird and is causing it to break, but I dont know for sure. This works in firefox.
Upvotes: 0
Views: 59
Reputation: 216
Yes, you can.
var myInput = document.getElementById('ourInput');
if(myInput.value.length == 0)
myInput.value = "Empty";
Note: myInput.value =="" will too.
Upvotes: 1
Reputation: 2329
Yes you can, and it will not create any impact on it Try this
$("input").keypress(function(){
//do your stuff
});
Or
<input type="text" onkeypress="myFunction()">
function myFunction() {
alert("You pressed a key inside the input field");
}
Upvotes: 1