tags:

views:

32

answers:

4

Hello,

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.

Thank you

A: 

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?

Pekka
Hello Pekka,Please see the related question: http://stackoverflow.com/questions/3606118/jquery-why-the-validation-rule-doesnt-support-predefined-value
q0987
+1  A: 

You can use Javascript.

For example, using jQuery:

$(':text').val('1000');

However, this won't be any different from using the value attribute.

SLaks
That won't actually set the default value. The DOM property, *defaultValue*, would be necessary for that.
Andy E
Actually, this is different from using the `value` attribute. View Source will not have `value="1000"` in it. Viewing rendered source still will, but regular source will not.
Ryan Kinal
Yes, this is an alternative way. However it still doesn't fix my original problem.http://stackoverflow.com/questions/3606118/jquery-why-the-validation-rule-doesnt-support-predefined-value
q0987
@q087: See my answer to your other question; you have a different problem.
SLaks
Hello SLakes,Please check up my follow-up post.thank you
q0987
A: 

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.

Chuck Conway
+1  A: 

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>
Guffa