How to add additional fields to form before submit?

Spook

Is there a way to use javascript and JQuery to add some additional fields to be sent from a HTTP form using POST?

I mean:

<form action="somewhere" method="POST" id="form">
  <input type="submit" name="submit" value="Send" />
</form>

<script type="text/javascript">
  $("#form").submit( function(eventObj) {
    // I want to add a field "field" with value "value" here
    // to the POST data

    return true;
  });
</script>
Suresh Atta

Yes.You can try with some hidden params.

  $("#form").submit( function(eventObj) {
      $("<input />").attr("type", "hidden")
          .attr("name", "something")
          .attr("value", "something")
          .appendTo("#form");
      return true;
  });

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Force user to fill all fields before enabling form submit

Angular JS: Validate form fields before submit

How to add to the form a virtual fields

How on trigger onBlur before form submit

How to add some additional fields to EKEvent

How to add additional fields to form after submit

How to add additional context to a django form widget

How to not submit form if there are validation fields outstanding?

Submit form fields overlapping

jQuery enable Submit button only if all form fields has class before form submit

Add additional fields to form after click - the node before which the new node is to be inserted is not a child of this node

Add more fields in a PHP form and submit

How to add additional classes to django form field

Dynamically fill form fields based on other responses before submit

jQuery submit additional form field

JS output all checked input fields values before form submit

How to add checkbox before submit button?

How to add additional fields to user documents (not in profile)?

How to add confirm box before submit

sequelize - how to do add additional fields to through

How to check validation form before submit in jQuery?

Validate required fields before JQuery submit form

Validating fields before submit

How to add validation to user input before they submit

How to loop multiple form fields in a table then submit

Angularjs - dropdown list inside an inserting form: how to add an item to the dropdown list before submit the form?

How to add additional input with value in modal before form submit in laravel

Trying To Match Two Fields Before Form Submit With Javascript

Trying to add with jQuery action for a form before submit