Reputation: 6114
<select id="paymenttype">
<option value="">---Select---</option>
<option>100</option>
<option>200</option>
<option>300</option>
<option>400</option>
<option>500</option>
</select>
<input type="text" id="check" value="" readonly/>
<input type="text" id="update" value="" />
JS
$("#paymenttype").change(function(){
$("#check").val($('#paymenttype option:selected').text());
});
$("#check").change(function(){
alert("soul");
$("#update").val(0);
});
As shown in the code $("#check").change(function()
it doesn't work? what function should i use in order to Jquery work? when there is change in the input text box check i am going to add? this is just an example
Upvotes: 3
Views: 72
Reputation: 35793
You just need to manually fire the change event when you set the value:
$("#paymenttype").change(function(){
$("#check").val($('#paymenttype option:selected').text()).change(); // <-- HERE
});
http://jsfiddle.net/infernalbadger/e6yEd/7/
You could add a tiny plugin so you can set the value and fire the change event at the same time in a single call.
This way you just call $("#check").changeVal($('#paymenttype option:selected').text());
:
(function($) {
$.fn.changeVal = function(value) {
return this.val(value).change();
};
})(jQuery);
http://jsfiddle.net/infernalbadger/e6yEd/11/
Upvotes: 4
Reputation: 1166
Use trigger function for run change() handler on '#check' http://jsfiddle.net/fliptheweb/e6yEd/8/
Upvotes: 0
Reputation: 17522
Try adding the trigger
$("#paymenttype").change(function(){
$("#check").val($('#paymenttype option:selected').text()).change();
});
note the .change()
at the end of the second line
Upvotes: 1