Dynamically add extra input fields to html form

How can I dynamically add extra input fields to the following html form?

 <form action="submit.php" method="post">
        <input type="text" name="question" placeholder="Question" required /><br>
        <select name="mediatype">
            <option value="">Select Media Type</option>
            <option value="1">None</option>
            <option value="2">Image</option>
            <option value="3">Video Link</option>
            <option value="4">Video Embed</option>
        <input type="text" name="media" placeholder="Link">
        <input type="hidden" name="surveyid" value="<?php echo $surveyid;?>"/>
        <input type="hidden" name="submittype" value="3"/><br>
        <input type="hidden" name="questiontype" value="1"/><br>
        <input type="submit" value="Save Question"/>
LVL 12
Nathan RileyFounderAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

leakim971Connect With a Mentor PluritechnicianCommented:
Test page : http://jsfiddle.net/t7tN4/

$(document).ready(function() {
   //$('<input type="text" name="textbox1" />').appendTo("form");
    $('<input type="text" name="textbox1" value="new" />').insertBefore("input:submit");

Open in new window

Nathan RileyFounderAuthor Commented:
That doesn't actually work the way expected.

I may have not explained correctly.

I'm looking for a completely separate button I would click that would add an additional input field to the form.
Did you understood the code?
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Nathan RileyFounderAuthor Commented:
What you posted on jfiddle didn't seem to do anything?
It add a new field...
Nathan RileyFounderAuthor Commented:
Ah it seems what you posted was for it to insert an extra field when the page is loaded.  I need it to be done when  I click a button, but I'm not sure how to modify to do so?
I dont see any button in your HTML let me think you want this clicking on a button.
Did you understood the code provided or do you just need someone to code for you?
Nathan RileyFounderAuthor Commented:
Yes I figured it out with some tweaking.


Now I'm going to open a new question.  How can I make the name of the new field go up in increments on 1 as I continue to add them?

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.