[html] How to define a default value for "input type=text" without using attribute 'value'?

I need to give a default value for input type=text field as follows:

<input type="text" size="32" value="" name="fee" />

There is one way to give this default value as I know:

<input type="text" size="32" value="1000" name="fee" />

Here is the question: Is it possible that I can set the default value without using attribute 'value'?

As I know, if I set the enter the value 1000 manually, and then view the source through web browser the value is still empty. So I think there may be a method that I can use.

This question is related to html

The answer is


Here is the question: Is it possible that I can set the default value without using attribute 'value'?

Nope: value is the only way to set the default attribute.

Why don't you want to use it?


You should rather use the attribute placeholder to give the default value to the text input field.

e.g.

<input type="text" size="32" placeholder="1000" name="fee" />

The value is there. The source is not updated as the values on the form change. The source is from when the page initially loaded.


A non-jQuery way would be setting the value after the document is loaded:

<input type="text" id="foo" />

<script>
    document.addEventListener('DOMContentLoaded', function(event) { 
        document.getElementById('foo').value = 'bar';
    });
</script>

this is working for me

<input defaultValue="1000" type="text" />

or

let x = document.getElementById("myText").defaultValue; 

You can set the value property using client script after the element is created:

<input type="text" id="fee" />

<script type="text/javascript>
document.getElementById('fee').value = '1000';
</script>