How to add elements to a form before submitting? WITHOUT AJAX

Is there a way to add data to a form before submitting it?

or add this form to a formdata and submit the formdata (without .$post, .$ajax or
XMLHttpRequest). the formdata can be submitted as a normal form.

14 thoughts on “How to add elements to a form before submitting? WITHOUT AJAX”

  1. you can add any hidden input you want:

    <input type="text" name="my_hidden_input" value="my_value" id="hidden_input" hidden/>

    and change the value whenever you want (on form submit or after page gets load)

  2. <form onsubmit="return addfield();" id="myform">

    <input type="text" name="txtname" value="Your name">

    <input type="submit" name="btnsubmit" value="Submit">



    function addfield(){

    var oldhtml=document.getElementById("myform").html();

    var newhtml='<input type="text" name="txtcity" value="Your city">';




  3. You could do form submit event

    function test(){
     //do stuff here
     return true
    <form action="action.php" method="get" onsubmit="return test()">
     <input type="text" name="one"/>
     <input id="new_insert" name="new" type="text">
     <input type="submit">

Leave a Comment