Solved

Dynamically add extra input fields to html form

Posted on 2013-10-24
8
498 Views
Last Modified: 2013-10-24
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
Comment
Question by:N R
  • 4
  • 4
8 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39599037
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
 
LVL 11

Author Comment

by:N R
ID: 39599063
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
 
LVL 82

Expert Comment

by:leakim971
ID: 39599069
Did you understood the code?
0
 
LVL 11

Author Comment

by:N R
ID: 39599071
What you posted on jfiddle didn't seem to do anything?
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 82

Expert Comment

by:leakim971
ID: 39599074
It add a new field...
0
 
LVL 11

Author Comment

by:N R
ID: 39599076
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
 
LVL 82

Expert Comment

by:leakim971
ID: 39599082
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
 
LVL 11

Author Comment

by:N R
ID: 39599093
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now