Help with using finding dom values using jquery .change function

I have a table with each row representing a member. I’m trying to figure out how to get the values (in comments below) from that row when the user selects from that rows drop down.

			<tr class="success" id="1"> 
				<th scope="row">
					<i class="fa fa-user ready"></i>
				</th> 
				
				<td class="name">Member Name</td> 
				
				<td>
					<select class="changeStatus form-control input-sm">
						<option>Ready</option>
						<option>Ready</option>
						<option>Enroute</option>
						<option>If Absolutely Needed!</option>
						<option>Out</option>
					</select>
				</td> 
				
				<td>
					<a href="tel:555-555-5555">
						<i class="fa fa-phone-square"></i>
						Call
					</a>
					<a href="sms:555-555-5555">
						<i class="fa fa-mobile"></i>
						Text
					</a>
				</td> 
			</tr>

			<tr class="success" id="2">
			 . . . 
			</tr>

			<tr class="success" id="3">
			 . . . 
			</tr>


			<script type="text/javascript">
			  $(document).ready(function() {
					
					
			     $('.changeStatus').change(function(){
			           var status = $(".changeStatus").val();

			           // how to get id of parent tr

			           // how to get value of that particular dropdown selected

			           // how to get the value of class name or any of the values inside of the parent tr
			           alert(status);     
			      });

			   }); //ready(function
			</script>

Thanks

Hey there,

Best to use delegated events which means you need one listener that can catch events for all rows.
event.target inside the function is the element that triggered the event

$('table').on('change', '.changeStatus', function(event) {
   var $select = $(event.target);

   // how to get id of parent tr
   var tr = $select.closest('tr')[0];
   var id = tr.id;
   var className = tr.className;

   // how to get value of that particular dropdown selected
   var value = $select.val();
   alert(value);
});
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.