Best way to submit UL via POST?

<ul>
    <li>Apple<input type='hidden' name='fruits[]' value='Apple'/></li>
    <li>Pear<input type='hidden' name='fruits[]' value='Pear'/></li>
    <li>Banana<input type='hidden' name='fruits[]' value='Banana'/></li>
</ul>

When submitted, you'll get an array in $_POST named fruits with those value.


Something like that (dynamic construction of the ul content):

<html>
<head>
    <title>S.O. 3287336</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
        $('#add').click(function() {
            var li = $('<li></li>').text($('#edit').val());
            $('#ul').append(li);
        });

        $('#addForm').submit(function() {
            var ul = "";

            $('#ul li').each(function() {
                ul += $(this).html() + ";"
            });

            alert("About to submit: " + ul); 
            return false; // don't submit
        });
    });
    </script>
</head>
<body>
<ul id="ul">
</ul>
<form id="addForm">
    <input type="text" name="edit" id="edit" value=""/>
    <input type="button" id="add" value="Add"/>
    <input type="submit" id="submit-btn" value="End"/>
</form>
</body>
</html>

Tags:

Php

Jquery