I have a textbox and a button. When I click the button, it sets certain value in the textbox. I want to submit the page whenever the value of the textbox is changed.
Ple
You're changing the value of .set
programatically, so the event doesn't fire. You have to trigger it manually:
$('.set').val('Why am I not getting the alert saying - Changed! ').change();
Programmatically changing the value of an input doesn't fire its change event. You'll have to do that yourself using .trigger('change')
(or just .change()
) at the same time as changing its value:
$('.set').val('Why am I not getting the alert saying - Changed! ').trigger('change');
You need to do this, when you are setting or changing the value of the text input chain it with .change()
too:
$("#click").click(function () {
$('.set').val('Why am I not getting the alert saying - Changed! ').change();
}); //-------------------------------------this one here-------------^^^^^^^^^
So whenever you set the input value this way the change event will be triggered right after click.
May be this could help
$("input").on('change keyup', function () {
alert("Changed!");
});
$(document).ready(function () {
$("input").change(function () {
Submitform();//Function for submitting form
});
$("#click").click(function () {
$('.set').val('Why am I not getting the alert saying - Changed! ');
Submitform();//Function for submitting form
});
});
Function for submitting the form
function Submitform(){
$("#YourformId").submit();//Submits your form
}
you can achieve like
$('.element').val('value').change(function(){
$("#form").submit();
});
http://jsfiddle.net/senstar2/CHjL5/5/
Fire the event manually after setting the value using the change()
function.
$(document).ready(function () {
$("input").change(function () {
alert("Changed!");
});
$("#click").click(function () {
$('.set').val('Why am I not getting the alert saying - Changed! ');
$('.set').change(); //Manual fire of event.
});
});
Working Example http://jsfiddle.net/RUdu2/