Send multiple values in an input to PHP, using jQuery AJAX

Asked

Viewed 824 times

3

I have a script to insert several items in a list of a form, using Ajax.

For each element inserted in this list, a next one must be added.

After inserting X elements, it should take all values and play on only one input, adding to the end of each element as a tag br/, for via PHP send to Mysql.

Ex:

<label>Insira os valores</label>
<ul>
 <li>elemento 1</li>
 <li>elemento 2</li>
 <li>elemento 3</li><span>+ adiciona proximo</span>
</ul>

The submit POST should generate an array (element1+element2+element3) by adding an br/ at the end of each element, and sent only in one input name="elementos"

  • 2

    And what’s the problem you’re having? How far have I been able to go? Where are your inputs?

  • I don’t know if I understand but want to send all the elements added to the list in an array and so send? Are you using a form? How this will be used?

1 answer

3

You can have a structure more or less of the type:

<label>Insira os valores</label>
<ul id='lista'>
 <li class='item'>elemento 1</li>
 <li class='item'>elemento 2</li>
 <li class='item'>elemento 3</li> 
 <span>+ adiciona proximo</span>
</ul>

And then the code

var elementos = '';
$('#lista>li').each(function()
           {
              elementos += $(this).html() +"<br/>";                                                             
           });
$('#lista').append(elementos);

Look here

And then you use jQuery’s own function for ajax at this link.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.