One way would be to check if the value
is equal to an empty string, and if so, manually set the value
to Price
. Note that this will require removing the type="number"
restriction.
document.getElementsByTagName('input')[0].onkeydown = function() {
if (this.value == '') {
this.value = "Price ";
}
}
<input class="textfield numberField font" name="Price" placeholder="Price">
If you only want to allow numbers, then you could add a pattern
validation of something like pattern="Price [0-9]"
:
document.getElementsByTagName('input')[0].onkeydown = function() {
if (this.value == '') {
this.value = "Price ";
}
}
<form>
<input class="textfield numberField font" name="Price" placeholder="Price" pattern="Price [0-9]">
<input type="submit">
</form>
Keep in mind that both approaches would have the word Price
in the value
(which may be unintended). Creating a <label>
may be more appropriate for your situation.