admin管理员组文章数量:1415673
In a form I have a button as input/submit. When I submit the value of the button is send.
if I change to input/button instead and do the submit via JQuery
i.e. $("form").submit()
the form is submitted but the value of the button is not send. Why? How could I fix this?
<form name="myform" id="myform" action="http://localhost/mypage.html" method="POST" >
<input type="button" id="btn" value="Actual value" name="save" >
</form>
$(document).ready(function() {
$("#btn").click( function() {
$("myform").submit();
}
}
In a form I have a button as input/submit. When I submit the value of the button is send.
if I change to input/button instead and do the submit via JQuery
i.e. $("form").submit()
the form is submitted but the value of the button is not send. Why? How could I fix this?
<form name="myform" id="myform" action="http://localhost/mypage.html" method="POST" >
<input type="button" id="btn" value="Actual value" name="save" >
</form>
$(document).ready(function() {
$("#btn").click( function() {
$("myform").submit();
}
}
Share
Improve this question
edited Nov 14, 2023 at 20:35
isherwood
61.2k16 gold badges122 silver badges170 bronze badges
asked Aug 28, 2013 at 16:19
JimJim
19.6k41 gold badges146 silver badges266 bronze badges
3
- 2 Because you are not submitting the form with the button click. – epascarello Commented Aug 28, 2013 at 16:20
- It should be a submit button to post the value of submit also – Manu M Commented Aug 28, 2013 at 16:22
-
What would be wrong with the
<input type="submit">
button? Please explain the reason why you want to use jQuery for submitting. – Bergi Commented Aug 28, 2013 at 16:52
5 Answers
Reset to default 4Buttons are not the same as inputs--that's why the button doesn't add to the form submission. You could add an input of type hidden
with the value you want next to the button.
Otherwise you would have to use JavaScript to grab the button after the form has been submitted to get its value.
try with this code
$(document).ready(function() {
$("#btn").click( function() {
$("myform").submit();
});
});
You can use input="submit" button with preventDefault(); function if you want to conditionally check the form submission
$("#btn").click(function(event){
if(truePart){
$(this).unbind('click').click();
}else{
event.preventDefault();
alert("Please fill the required fields");
}
});
Try name="Actual Value" , then try accessing the value on server using POST['name'] , it will let you to have your actual value.
It looks like your javascript is syntactically incorrect.
Your code
$(document).ready(function() {
$("#btn").click( function() {
$("myform").submit();
}
}
should look like this
$(document).ready(function() {
$("#btn").click(function() {
$("myform").submit();
});
});
You're missing two closing parentheses and two semicolons.
If that doesn't help, try this for your button:
<input type="submit" name="save" value="Actual Value" />
Make sure your server-side code is prepared to accept a save
parameter, as well. Can't send code to something that doesn't want to receive it!
本文标签: javascriptWhen I use input typebutton the value of it is not sent to the serverStack Overflow
版权声明:本文标题:javascript - When I use input type=button the value of it is not sent to the server - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745216017a2648170.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论