Mawia HL
Mawia HL

Reputation: 3665

Setting Default value of input textbox in Jquery EasyUI dialog

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

Upvotes: 1

Views: 9301

Answers (7)

OTG
OTG

Reputation: 51

I too had this problem and it was solved using the following

First my input was in the form like this:

<input name="hostFirstName" id="hostFirstName"  class="easyui-textbox">

I needed to load content from the db then pre-fill the input with this data so the user could edit the content. I used the following javascript.

NOTE: i didn't hide this away inside an anonymous function() and it is working. I tested this first from the F12 console to make sure it was working before changing my code.

//populate with existing data
$('#hostFirstName').textbox('setValue', "Is this working?");

The docs on jeasyui.com don't provide this example when you look at the textbox api reference. But they do provide an example when looking at the combobox (http://www.jeasyui.com/documentation/index.php#) the combobox and textbox use the same setValue method.

Hopefully this works for you like it does for me.

Upvotes: 0

Mawia HL
Mawia HL

Reputation: 3665

I found the answer here. The trick is to use the code inside $(function(){});

$(function(){
    var m=300;
    $('#d_amount').textbox('setValue', m);
});

Upvotes: 0

UserProg
UserProg

Reputation: 639

I have found your thread because I am also having the same issue and I have just across this thing today. Your case is a little bit different (maybe) then my case because you want to set the default which can be changed by the user later (I believe). In my case, the value will be fixed (will not be changed) so I have applied a trick and hopefully it can give some ideas to you and others who are having same issue. Please refer below:

In first page says pageA.php:

<select name="myThing" id="myThing">
    <option value="Your Desired Value" selected="selected">Something</option>
</select>

Still in the same page, under your $(document).ready( function(){ put the code below:

$("#myThing").val($("#myThing option:first").val());

That code is to make sure your desired value appears at the first row in the drop down. I say this because in EasyUI it seems when I use drop down and put single option, the first row will be blank and the second row will hold your input. So that is the trick to ensure your desired value appears on top and selected. Put the select under the form then during normal post, you will be able to get the value of it in the posted page. Enjoy. Thank you.

Suggestion: if your value can be changed by user, use placeholder and you can hide the default value from user using my trick.

Upvotes: 1

Hilarius L. Doren
Hilarius L. Doren

Reputation: 757

use this code to set the value inside $(document).ready(function(){}

  ....
  $("#d_amount").numberbox('setValue','300');
  ....

if still not working, just try to set name and id as the same name and id

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

I am always working with this numberbox and it's working

Upvotes: 1

R A Khan
R A Khan

Reputation: 187

Use the below code

$("#d_amount").numberbox({
    min:0,
    precision:2,
    value:300

})

Reference : numberbox

Or try this one

$("#d_amount").textbox({
    buttonText:'Search',
    iconCls:'icon-man',
    iconAlign:'left',
    value:"300"
});

Reference : textbox

Upvotes: 2

RobG
RobG

Reputation: 147403

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;

Upvotes: 3

Mesho
Mesho

Reputation: 45

try this

 document.getElementById("d_amount").value=m;

you don't need innerHTML

Upvotes: 0

Related Questions