Reputation: 73
I am working on using jQuery to submit a form without having to refresh a page which I am new at. So far i have everything working except i have a dynamic amount of dropdown menus which would be named loot[0], loot[1], etc. however i can not get the loot[] variable to pass through the jQuery.
Here is the dropdown
<select class="search" name="loot[]" id="loot[]">
<option class="search" value="">--</option>';
$stmt = $conn->query("SELECT * FROM re_tbllootlist WHERE active = 1 ORDER BY LootName");
while($row = $stmt->fetch()){
echo "<option class='search' value='".$row["LootKey"]."'>".$row["LootName"]."</option>";
}
</select>
More dropdowns are added with jQuery which would create the loot[0], loot[1], etc.
Which then would be added to the post data in jQuery with this:
post_data = {
'info_planet' : $('select[name=planet]').val(),
'info_mob' : $('input[name=mob]').val(),
'info_x_axis' : $('input[name=x_axis]').val(),
'info_y_axis' : $('input[name=y_axis]').val(),
'info_description' : $('textarea[name=description]').val(),
'info_loot' : $('select[name=loot[]]').val()
};
I have tried several things to get this to work however i can not get this to work.
Upvotes: 0
Views: 69
Reputation: 34244
jQuery cannot recognize this selector select[name=loot[]]
because of []
.
If you look in your developer console, you will see the following error:
Uncaught Error: Syntax error, unrecognized expression: select[name=loot[]]
Just enclose the name in quotes like this
$('select[name="loot[]"]').val()
Upvotes: 1