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>
        </select>
        <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"/>
    </form>
LVL 12
Nathan RileyFounderAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
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

0
 
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.
0
 
leakim971PluritechnicianCommented:
Did you understood the code?
0
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?
0
 
leakim971PluritechnicianCommented:
It add a new field...
0
 
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?
0
 
leakim971PluritechnicianCommented:
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?
0
 
Nathan RileyFounderAuthor Commented:
Yes I figured it out with some tweaking.

http://jsfiddle.net/t7tN4/2/

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?

http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Jquery/Q_28276770.html
0
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.