Anuket
Anuket

Reputation: 339

Do not show default value of the input field

I have an input field

 <input id='spe_count' type="text" placeholder="number" class="form-control" data-original-title="" title="">

and as I need it to be by default with value -1 I am assigning it with jQuery

 $("#spe_count").val('-1');

And I get this input field and see this value -1 inside it, but what I want is that this input is with value -1, but on the page it would be empty or with placeholder. And when I am changing values, I'd like to do so, that deleting value, emptying the box means that it is default value -1 (not typing minus one , but simply deleting all the values mean this is minus one)

Is this possible?

Upvotes: 0

Views: 1172

Answers (1)

R A Khan
R A Khan

Reputation: 187

#("#spe_count").click(function(){
    var value= $(this).val();
    if(value.length < 1){
       $(this).attr("value", -1);
    }
});

The above code will serve your purpose.

Upvotes: 1

Related Questions