Multiply form with javascript?

Discussion in 'JavaScript' started by Sipifi, Jan 15, 2009.

  1. #1
    Hey all,

    I have a form on my website which is used to send me link ideas. Recently i had a request to have a multiple submission option. So that they could send me more than 5 links at the same time without having to click submit for every single one. Hope you're still following me here :p

    Is that possible with javascript? And if so, any direction you can point me in?
     
    Sipifi, Jan 15, 2009 IP
  2. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #2
    This is just a concept, probably not functional code
    <script type="text/javascript">
    	var count = 3; // however many forms you want to load the page with
    	function addForm(count){
    		var formarea = document.getElementById("formArea");
    		count++;
    		var add_this = "<input type='text' name='link_"+count+"' /><br/><br/>";
    		formarea.innerHTML = formarea.innerHTML + add_this;
    	}
    </script>
    <div id="formArea">
    	<input type="text" name="link_1"><br/><br/>
    	<input type="text" name="link_2"><br/><br/>
    	<input type="text" name="link_3"><br/><br/>
    </div>
    <a href="#add_form" onclick="addForm(count)">Add More Fields</a>
    Code (markup):
    just a thought, who knows :p
     
    crath, Jan 15, 2009 IP
  3. Sipifi

    Sipifi Well-Known Member

    Messages:
    530
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    155
    #3
    I'll give it a try and play around with it :) Thanks

    Edit: It does indeed work as far as adding more fields go :) Which is exactly what i need. Now to come up with a way to change it so that i can use it hmm :p Thanks again :)
     
    Sipifi, Jan 16, 2009 IP
  4. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #4
    in php, just use a loop and check something like if(isset($_POST['link_'.$i)){

    and then keep increasing I so it keeps checking for more forms until it gets to one that hasn't been set
     
    crath, Jan 16, 2009 IP
    Sipifi likes this.
  5. fatedesign

    fatedesign Peon

    Messages:
    38
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Why not do it in PHP?
     
    fatedesign, Jan 20, 2009 IP
  6. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #6
    because he wanted users to be able to instantly give users the option to add fields
     
    crath, Jan 21, 2009 IP