Link to home
Start Free TrialLog in
Avatar of Jazzy 1012
Jazzy 1012

asked on

Get value of drop-down when there are multiple of them

I have this code:
  <div class="adddiv">
				     <p class="deliveryText OldStandard">Delivery </p>
						<form>
						<p class="delivery_days">Monday
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
						 </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 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;</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>

Open in new window


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
Avatar of Zakaria Acharki
Zakaria Acharki
Flag of Morocco image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jazzy 1012
Jazzy 1012

ASKER

So none of these worked, except for var fridayOption    = $('.fridaySelect option:selected').val(); but this only returned the value of the first one.
I think because the Confirm button is all the same code as well. Im not sure.
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
Actually i had copied it wrong! thank you both!
You're welcome, glad we could help.