Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting submit value in jQuery submit

Tags:

jquery

forms

I want to use jQuery to submit my form and i can do that like so

  $('#myform_id').submit();

and thats all good but normally someone clicks a submit button than that submit button has a value so when I do the submit via jQuery I also need to set a submit value how do i do that ?

EDIT

as noted by some answers I could do this by simulating a user click but I don't want to do that I want to pass the submit value when I use the .submit() command if that is possible

ultimately the submit using ajax form

** Clarifying **

ok so I have jQuery setup to use jquery validate and has a submit handler like so

$("#myform_id").validate({
    submitHandler: function() {
        run_ajax(obj);
    }
});

then that calls I function i call run_ajax passing and object containing information about what type of ajax i want and what have you.

and ultimately runs this

obj.formitem.ajaxSubmit({
    dataType:'json',
    data: obj.pdata,
});

where

  obj.formitem == $('#myform_id');

so when the form is submit all that happens all good.

so I load the page with this form into jquery dialog and I want them to be able to click a button in the dialog that triggers the form submit and also tells the form what type of submit was requested

hopefully this is clear now sorry for confusion

like image 579
mcgrailm Avatar asked Aug 20 '10 13:08

mcgrailm


People also ask

Is submit in jQuery?

jQuery submit() MethodThe submit event occurs when a form is submitted. This event can only be used on <form> elements. The submit() method triggers the submit event, or attaches a function to run when a submit event occurs.

How can create Submit button in jQuery?

Answer: Use the jQuery submit() Method You can use the submit() method to submit an HTML form (i.e. <form> ) using jQuery. The jQuery code in the following example will submit the form on click of the button (i.e. the <button> element) which has the type attribute set to button (i.e. type="button" ).

How do I add a submit button to a form?

It is also created using HTML <input> tag but type attribute is set to button. You can try to run the following code to use submit button to submit and reset a form. Under the action, attribute add the file, where you want to reach after clicking Submit button.


1 Answers

https://stackoverflow.com/a/993897/215887 worked for me

Well actually I did it this way:

$('<input />').attr('type', 'hidden')
              .attr('name', 'myButton')
              .attr('value', 'MyButton')
              .appendTo('#my-form');
$('#my-form').submit();
like image 67
brian_d Avatar answered Sep 28 '22 06:09

brian_d