How to define a default value for "input type=text" without using attribute 'value'?
Solution 1:
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" />
Solution 2:
You can change the name
attribute by id
, and 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>
Solution 3:
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?
Solution 4:
You can use Javascript.
For example, using jQuery:
$(':text').val('1000');
However, this won't be any different from using the value
attribute.
Solution 5:
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>