I'm writing a basic recipe organization application and I would like to be able to dynamically add additional items to the list of ingredients using Ajax.
This is what one ingredient <fieldset>
looks like:
<fieldset id="ingredient_item_0">
Ingredient <input id="ingredient_0" type="text" size="20" />
<div id="ingredient_list_0" style="" class="autocomplete"></div>
Amount <input id="amount_0" type="text" size="5" />
Unit <input id="unit_0" type="text" size="20" />
<div id="unit_list_0" class="autocomplete"></div>
Notes <input id="notes_0" type="text" size="20" />
<script type="text/javascript">
new Ajax.Autocompleter('ingredient_0','ingredient_list_0','ingredients.php', {'method':'get', 'paramName': 't'});
new Ajax.Autocompleter('unit_0','unit_list_0','units.php', {'method':'get', 'paramName': 't'});
</script>
</fieldset>
What is the best way (using prototype and scriptaculous) to add additional copies of this <fieldset>
with the accompanying JavaScript to the page making sure each one has a unique ID?