Setting Default value of input textbox in Jquery EasyUI dialog

Mawia HL picture Mawia HL · Oct 28, 2014 · Viewed 8k times · Source

I have googled and looked throughout the whole documentation and could not figure out why value of input text is not shown. I am using FireFox latest version and below is what I have done so far.

 <input name="amount" class="easyui-validatebox" id="d_amount" value="">

In regular html or php page we can give value="300" to set default value, but in EasyUI, it is not possible. So I was thinking possible alternative like below:

  <script>
   var m = '300';
   document.getElementById("d_amount").value.innerHTML=m;
  </script>

Nothing is shown and I am not getting any error. Any EasyUI expert, please help me.

NOTE: this input field is inside the dialog

Answer

RobG picture RobG · Oct 28, 2014

To set the default value, you have to set the value attribute. However, that does not necessarily update the value property so you need to do both. So given:

<input name="amount" class="easyui-validatebox" id="d_amount" value="">

set the default value by setting the value attribute:

var input = document.getElementById('d_amount')
input.setAttribute('value', 'whatever');

now set the value property:

input.value = 'whatever';

Note that you can also get a reference to the input as a member of the form that it's in:

var input = document.formName.d_amount;