Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to simply send a request parameter with jquery form submit?

I am able to submit a form as Post type using the following in my javascript:

$("#receiptsForm").submit();

But I also want send across a parameter myparam as well with the request which I'll be retrieving in my spring controller using httpServletRequest.getParameter("myparam"):

var myparam = "abc";
$("#receiptsForm").submit();

What's the best I can do?

like image 230
user2918640 Avatar asked Nov 30 '22 19:11

user2918640


2 Answers

try this

function form_submit()
{
      //var myparam = "abc";

     // add hidden field to your form name="myparam" and value="abc"
      $('#receiptsForm').append('<input type="hidden" name="myparam " value="abc" />');
      $("#receiptsForm").submit(); 
}
like image 155
Satish Sharma Avatar answered Dec 06 '22 20:12

Satish Sharma


Try this,

var input = $("<input>")
               .attr("type", "hidden")
               .attr("name", "mydata").val("bla");
$('#receiptsForm').append($(input));
$('#receiptsForm').submit();
like image 26
dhana Avatar answered Dec 06 '22 19:12

dhana