Pass extra variable when submitting a form using jQuery

前端 未结 5 2236
野性不改
野性不改 2021-02-12 12:53

I have a form in which the Submit button does not sit within the

tags. The submit button has an click handler to submit the form via jQuer
5条回答
  •  独厮守ぢ
    2021-02-12 13:15

    One thing you could do is use the onsubmit attribute to have javascript inject a post field into the form with the value of the submit button right as it is submitted. You'd have to do this with a hidden input field, but you'd only add the input field right after the user clicked the submit button -- so the input field wouldn't exist there from the beginning (hopefully this satisfies your requirements). So something like:

     function submitHandler()
     {
         submitVal = $('#submitButton').val();
         $('#myForm').append("");
         return true;
     }
    

    Which would stick in the extra value right as the button was clicked.

提交回复
热议问题