1
votes

I know that there is a lot of topics regarding this question, but believe me, I read all of them and none worked with me :/

Btw I use laravel-4

My form:

 <div id="input1" style="margin-bottom:4px;" class="clonedInput">
          Name: <input type="text" name="name1" id="name1" />
      </div>

      <div>
          <input type="button" id="btnAdd" value="add another name" />
          <input type="button" id="btnDel" value="remove name" />
      </div>

My Js:

    ('#btnAdd').click(function() {

            var num     = $('.clonedInput').length;
            var newNum  = new Number(num + 1);

            var newElem = $('#input' + num).clone().attr('id', 'input' + newNum);

            newElem.children(':first').attr('id', 'name' + newNum).attr('name', 'name' + newNum);
            $('#input' + num).after(newElem);
            $('#btnDel').attr('disabled','');

            if (newNum == 5)
                $('#btnAdd').attr('disabled','disabled');
        });

        $('#btnDel').click(function() {
            var num = $('.clonedInput').length;

            $('#input' + num).remove();
            $('#btnAdd').attr('disabled','');

            if (num-1 == 1)
                $('#btnDel').attr('disabled','disabled');
        });

        $('#btnDel').attr('disabled','disabled');

And on my controller: (just to check if is there anything on the var)

$child = Input::get('name2');
    return $child;

As you can see, I'm trying to return the second name only, cause the first works (cause its static, not generated by the jquery)

My question is, is there anything wrong? How can I retrieve the value from the other generated fields (up to 5) (name1 works fine[cuz static], name2,name3,name4,name5)?

Thanks in Advance, I've a whole back-end waiting for me :/.

Help me StackOverflow, you are my only hope (got the quote?) haha ;)

http://pastebin.com/VpWq0x43 (my whole view / form page)

1
How you post data ? Ajax or Submit. - dotnetstep
Your code worked fine for me. After a little refactor. When you run it, you do see the new form inputs being generated, right? Is the problem only that your server post is not getting the "correct" form data? - mr rogers
What you want exactly ? Do you want array or if want to dynamic then you have to take care of many thing and also pass additional information like max index value. - dotnetstep
Yes, whenever I click the add another name it generates and I checked within the source-code view from browser, yes, but the thing is none, nada, 0 data is returned, not even null, like the field didn't exist in the first place :/ - SylaQo
The browser "source-code" view will probably not get updated. But if you run a javascript console in your browser and do a "$('.clonedInput').length" I bet you'll see the new items. - mr rogers

1 Answers

0
votes

The solution was moving my code up after my 4th or 5th input. A problem with Div's maybe?