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.
HTMLJavaScriptPHP

Avatar of undefined
Last Comment
Zakaria Acharki

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Zakaria Acharki

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Chris Stanyon

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
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.
Chris Stanyon

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
Jazzy 1012

ASKER
Actually i had copied it wrong! thank you both!
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Zakaria Acharki

You're welcome, glad we could help.