Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

for input type="number" how to set default value to 0

For a textbox that accept numbers as shown below, how can the default value be set to 0?

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

Though the value in DB is null, it still shows 0 in textbox.

Any help would be appreciated.

like image 398
NiksJ Avatar asked Jan 21 '16 13:01

NiksJ


People also ask

How do you give a default value to 0?

right click on your database -- select design--select required column--in column properties, general tab you will see the "default value or binding". Mention 0 here.

How do I change the default form value?

On the Tools menu, click Form Options. Click Advanced in the Category list, and then click Edit Default Values. In the Edit Default Values dialog box, select the field whose default value you want to set.

How do you prevent a zero as the first character when typing in input type number?

keypress(function(evt) { if (evt. which == "0".


1 Answers

HTML attribute to set a default value is value:

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

You're setting this default value to null, and nothing (in HTML) can change it to zero (or anything else).
You must fix the value in your database, or in your template engine (something like {{model.PortNumber || 0}}).

At least, you can force your field to be filled with required attribute:

<input type="number" required value=""> 
like image 189
zessx Avatar answered Sep 29 '22 20:09

zessx