Neil P
Neil P

Reputation: 3190

Can input value artribute be defined as empty?

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

enter image description here

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

Answers (2)

anam
anam

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

The Mechanic
The Mechanic

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

Related Questions