admin管理员组文章数量:1289620
I have some javascript that submits to an HTML form in my app upon a "click" event like so....
google.maps.event.addListener(marker, 'click', function() {
$('form').submit()
});
However I want to change the data before I send it. Is this possible? I don't want to use Ajax $.post if I can help it. I just want to change what the form sends to my Rails controller before submit.
Thanks!
I have some javascript that submits to an HTML form in my app upon a "click" event like so....
google.maps.event.addListener(marker, 'click', function() {
$('form').submit()
});
However I want to change the data before I send it. Is this possible? I don't want to use Ajax $.post if I can help it. I just want to change what the form sends to my Rails controller before submit.
Thanks!
Share Improve this question asked Nov 26, 2011 at 18:56 thoughtpunchthoughtpunch 1,9375 gold badges25 silver badges41 bronze badges 1- Sure, just update the field values before calling ".submit()". – Pointy Commented Nov 26, 2011 at 18:58
2 Answers
Reset to default 6If you already have a field with name="search" you can change it's value like so:
google.maps.event.addListener(marker, 'click', function() {
$('form input[name="search"]').val( place.name );
$('form').submit()
});
Or if not:
google.maps.event.addListener(marker, 'click', function() {
$('form').append('<input type="hidden" name="search" value="'+place.name+'" />').submit()
});
Assuming place.name
is known like in your previous question.
You can update the value of specific fields by id before you call submit:
$("form #fieldID").val("Value you want to change");
本文标签: javascriptJquerysubmit()Changing Form Values before submitStack Overflow
版权声明:本文标题:javascript - Jquery.submit() - Changing Form Values before submit - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741468019a2380429.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论