I have many input field that post data when enter key is press i have done one thing that i find id to of selected button and want to pas with click event bt it gives error here is code
$(".text").bind("keydown", function(event) {
// track enter key
var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));
if (keycode == 13) {
var id=$(this).parent().find("input[type=submit]").attr('id');
(id).click(); // this one give error
return false;
} else {
return true;
}
});
(id).click(); this line gives error that id.click is not a function.what i m missing.
id
is a string.
Strings don't have a click
method.
Instead, you should submit the form directly:
$(this).closest('form').submit();
I think you are looking for:
$(this).closest("form").find("input[type=submit]").trigger("click");
There is no need to try to find the id
and create a different JQuery object. You will have a reference to what you are looking for with find("input[type=submit]")
.
In order to know for sure, we would need to see your markup in order to find the most effective way to find what element you are looking for,
You need to use the following:
$("#"+id).trigger("click");