[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 572
  • Last Modified:

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>
0
Nathan Riley
Asked:
Nathan Riley
  • 4
  • 4
1 Solution
 
leakim971PluritechnicianCommented:
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 RileyFounder/CTOAuthor 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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Nathan RileyFounder/CTOAuthor Commented:
What you posted on jfiddle didn't seem to do anything?
0
 
leakim971PluritechnicianCommented:
It add a new field...
0
 
Nathan RileyFounder/CTOAuthor 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 RileyFounder/CTOAuthor 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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now