Brave Type Brave Type - 5 months ago 16
HTML Question

Add input into form with jquery and submit

I want to add an input into form using JQuery, and then submit the form with pure HTML without using javascript.

<form method="post" action="" id="myform" >
<input type="hidden" name="example" value="done" />
<input type="submit" value="try" />

Here my JQuery line that add new input:

$('#myform').append("<input name="example2" value="done" type='hidden'/>");

My issue is when i submit the form, i can't get
input value ! help me to figure it out.


What you need to do is download jquery library or use the external google cdn library as the one i have used in my case in the head of your html file.

Ensure that you append the input on the form as the document loads. If you intend to submit your form to Php as the server side check if the form is posted and print the output. You should save your file with .php extension.

Try the solution below. Thanks

$(document).ready(function() {
        $("form#myform").append("<input name='example2' value='done' type='hidden'/>")
<script src=""></script>
    <form method="post" action="" id="myform">
      <input type="hidden" name="example" value="done" />
      <input type="submit" value="try" />