I have five ul lists that I am using and each list might have an input in it.
Here is an example:
<form id="testForm">
<ul id="1">
<li>TEST</li>
<li>Gender:
<select id="gender" name="gender">
<option value="0">Male</option>
<option value="2">Female</option>
</select>
</li>
</ul>
<ul id="2">
<li>TEST2</li>
<li>Gender2:
<select id="gender2" name="gender">
<option value="0">Male</option>
<option value="2">Female</option>
</select>
</li>
</ul>
</form>
What I am trying to do is get an array of the li text and if there is an input get the selected value of it.
With jquery I have tried this:
$('#testForm').submit(function() {
var optionTexts = [];
for (i = 1; i < 2; i++) {
$("#"+i).each(function() { optionTexts.push($(this).text()) });
}
alert(optionTexts);
return false;
});
Now the problem that I am having is it gives me a list of all the UL LI but it is also giving all the options not the selected option. How would I go about doing this?
Edit
I forgot to add the output that I am looking for. I want an output like this:
[1, TEST1, gender => male]
[2, TEST2, gender => female]