Jazzy 1012
asked on
Get value of drop-down when there are multiple of them
I have this code:
I want to be able to get the value of the select box, but its not working for some reason. the reason I want to do it through the attribute it because, there are multiple selections in a while loop and i had to differenate them by that way. But im open to any ideas, there are a total of 9 loops so 9 select boxes.
<div class="adddiv">
<p class="deliveryText OldStandard">Delivery </p>
<form>
<p class="delivery_days">Monday
</p>
<select class='mondaySelect' MondayOption= "<?php echo $new_counter;?>">
<?php
for($i=0;$i <= $qty_value; $i++)
{
echo '<option value="'. $i.'">'. $i .'</option>';
}
?>
</select>
<p class="delivery_days">Wednesday </p>
<select class='wednesdaySelect' WednesdayOption= "<?php echo $new_counter;?>">
<?php
for($i=0;$i <= $qty_value; $i++)
{
echo '<option value="'. $i.'">'. $i .'</option>';
}
?>
</select>
<p class="delivery_days">Friday </p>
<select class='fridaySelect' FridayOption= "<?php echo $new_counter;?>">
<?php
for($i=0;$i <= $qty_value; $i++)
{
echo '<option value="'. $i.'">'. $i .'</option>';
}
?>
</select>
</form>
<p class="meal_price priceInDiv">$<?=$new_price/100?></p>
<a class = "confirmbtn" onclick='post(<?=$new_id?>,"0")'>CONFIRM</a>
</div>
<script>
function post(mealId,uid){
var protein = $('.option-selected').attr('label_option');
var mondayOption = $('.mondaySelect').find('option:selected').attr("MondayOption");
alert(mondayOption);
var wednesdayOption = $('.wednesdaySelect :selected').attr('WednesdayOption').val();
var fridayOption = $('.fridaySelect :selected').attr('FridayOption').val();
if(mondayOption ==0 && wednesdayOption ==0 && fridayOption ==0){
$('#day_null').show();
//alert("You must select aday");
}else{
$.ajax({
method: "POST",
url: "/order/createSession",
data: { meal:mealId,protein:protein,monday:mondayOption,wednesday:wednesdayOption,friday:fridayOption},
success:function(){
location.reload();
}
})
}
}
</script>
I want to be able to get the value of the select box, but its not working for some reason. the reason I want to do it through the attribute it because, there are multiple selections in a while loop and i had to differenate them by that way. But im open to any ideas, there are a total of 9 loops so 9 select boxes.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What do you mean by the 'first one'. There is only one fridaySelect - and even if there were more than one, you're not doing anything in a loop, so it would only select the first one.
Maybe give us a little more information on what you're trying to do and we can give you a better idea of how to do it
Maybe give us a little more information on what you're trying to do and we can give you a better idea of how to do it
ASKER
Actually i had copied it wrong! thank you both!
You're welcome, glad we could help.
ASKER
I think because the Confirm button is all the same code as well. Im not sure.