Javascript submit does not contain submit button value
P粉957661544
P粉957661544 2023-10-22 09:40:15
0
2
468

Well this is not a question but just for my information (since I can think of about 4 different workarounds to make it work. However I have a form (nothing special) but the submit button has something to do with The specific value associated with it.

After submitting the form, I check the name.

if(isset($_POST['submitDocUpdate'])){ //do stuff

However, one time I tried to submit the form via Javascript instead of the submit button.

document.getElementById("myForm").submit();

Everything is working fine except 1 problem. When I look at the $_POST value submitted via the javascript method, it does not include SubmitDocUpdate. I get all other values of the form but not the submit button value.

Like I said, I can think of a few ways to fix it (using a hidden variable, checking isset on another form variable, etc.), but I just want to know if this is the correct behavior for Submit(), Because it doesn't seem very intuitive to me. Thanks in advance.

P粉957661544
P粉957661544

reply all (2)
P粉131455722

Use jQuery 1.0 or higher:

$('input[type="submit"]').click();

I was actually solving the same problem when I stumbled across this post. click() without any parameters triggers a click event on any element you select:http://api.jquery.com/click/

    P粉466290133

    Yes, this is the correct behavior ofHTMLFormElement.submit()

    The reason the submit button value is not sent is that HTML forms are designed to send the value of a submit button that is clicked (or otherwise activated). This allows for multiple submit buttons per form, for example in scenarios where you need "preview" and "save" actions.

    Since you are submitting the form programmatically, there is no explicit user action on the single submit button, so nothing is sent.

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!