For input type = "number", how to set the default value to 0

In a text box that accepts numbers as shown below, how to set the default value to 0?

<input name="smtpPort" type="number" id="smtpPort" size="30" maxlength="50" class="input-full" tabindex="4" value="{{model.PortNumber}}"> 

Although the value in the database is zero, it still shows 0 in the text box.

Any help would be appreciated.

+8
javascript html angularjs
source share
2 answers

HTML attribute to set the default value : value :

 <input type="number" value="1"> 

You set this default to null , and nothing (in HTML) can change it to zero (or anything else).
You must correct this value in your database or in your template (for example, {{model.PortNumber || 0}} .

At least you can make your field populate with the required attribute:

 <input type="number" required value=""> 
+7
source share
 <input name="smtpPort" type="number" id="smtpPort" size="30" maxlength="50" class="input-full" tabindex="4" value="{{model.PortNumber || 0}}"> 

I assume you are using AngularJS.

+3
source share

All Articles