Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try this:</p> <pre><code>&lt;!DOCTYPE HTML&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="content-type" content="text/html" /&gt; &lt;title&gt;Ingredients&lt;/title&gt; &lt;script type="text/javascript"&gt; &lt;!-- function selectIngredient(select) { var option = select.options[select.selectedIndex]; var ul = select.parentNode.getElementsByTagName('ul')[0]; var choices = ul.getElementsByTagName('input'); for (var i = 0; i &lt; choices.length; i++) if (choices[i].value == option.value) return; var li = document.createElement('li'); var input = document.createElement('input'); var text = document.createTextNode(option.firstChild.data); input.type = 'hidden'; input.name = 'ingredients[]'; input.value = option.value; li.appendChild(input); li.appendChild(text); li.setAttribute('onclick', 'this.parentNode.removeChild(this);'); ul.appendChild(li); } --&gt; &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;?php if ( isset( $_POST['ingredients'] ) ) { if ( !empty( $_POST['ingredients'] ) ) { echo '&lt;fieldset&gt;&lt;legend&gt;Your ingredients&lt;/legend&gt;'; foreach ( $_POST['ingredients'] as $ingredient ) { echo '&lt;p&gt;- ', $ingredient, '&lt;/p&gt;'; } echo '&lt;/fieldset&gt;'; } else { echo '&lt;p&gt;No ingredients selected!&lt;/p&gt;'; } } ?&gt; &lt;form action="" method="post"&gt; &lt;ul&gt; &lt;li onclick="this.parentNode.removeChild(this);"&gt; &lt;input type="hidden" name="ingredients[]" value="Cheese" /&gt; Cheese &lt;/li&gt; &lt;li onclick="this.parentNode.removeChild(this);"&gt; &lt;input type="hidden" name="ingredients[]" value="Ham" /&gt; Ham &lt;/li&gt; &lt;li onclick="this.parentNode.removeChild(this);"&gt; &lt;input type="hidden" name="ingredients[]" value="Mushrooms" /&gt; Mushrooms &lt;/li&gt; &lt;/ul&gt; &lt;select onchange="selectIngredient(this);"&gt; &lt;option value="Cheese"&gt;Cheese&lt;/option&gt; &lt;option value="Olives"&gt;Olives&lt;/option&gt; &lt;option value="Pepperoni"&gt;Pepperoni&lt;/option&gt; &lt;/select&gt; &lt;input type="submit" value="go" /&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload