I've asked this a couple times already, but I haven't been able to convey my question properly, so I figured I would try again:
I want to make a form. The structure will be:
<html>
<head>
<script type="text/javascript">
</script>
<style type="text/css">
ul {
list-style-type:none;
}
</style>
</head>
<body>
<input type="text" value="Menu 1 Name" />
<input type="button" value="Remove Menu" />
<ul>
<li><input type="text" value="Option 1" /><input type="button" value="Remove Option" /></li>
<li><input type="text" value="Option 2" /><input type="button" value="Remove Option" /></li>
<li><input type="button" value="Add Option" /></li>
</ul>
<input type="text" value="Menu 2 Name" />
<input type="button" value="Remove Menu" />
<ul>
<li><input type="text" value="Option 1" /><input type="button" value="Remove Option" /></li>
<li><input type="text" value="Option 2" /><input type="button" value="Remove Option" /></li>
<li><input type="button" value="Add Option" /></li>
</ul>
<input type="text" value="Menu 3 Name" />
<input type="button" value="Remove Menu" />
<ul>
<li><input type="text" value="Option 1" /><input type="button" value="Remove Option" /></li>
<li><input type="text" value="Option 2" /><input type="button" value="Remove Option" /></li>
<li><input type="button" value="Add Option" /></li>
</ul>
<input type="button" value="Add Menu" />
</body>
</html>
I need to be able to get the form data for the menu names and the menu options for however many menus and options there are. I was thinking about doing something along the lines of making a variable that is put into the id of the menu and another variable for the menu options and then doing a for loop that continues until it gets the information from all the forms.
The problem is that I want the menu ids and option ids to always be in order, no matter how many times they add or remove a menu. For example, let's say I have three options with ids of Menu1Option1, Menu1Option2, and Menu1Option3. If I remove the second option, it will show the first and third options. Since there are only two, I would want the third option's ID to become Menu1Option2. The only way I can think of to do this is to create a new variable for the amount of options every time they add a menu and then use the variable to determine the ids of the options and, when one is removed, re-id all the options after it based on the id of the option removed...
If you understand what I'm trying to do, can you tell me how to do it the right way please? I'm sure I'm quite off course here. I'm guessing that the better way would be to NOT id each menu and option but rather to make an array of them some how? It seems more suited to what I want, but I have no idea how to do it.