Reputation: 1655
So the following code:
$product_id = $(this).parent().parent().html();
Produces this:
<div class="right">
<input value="6" name="quantity" id="" maxlength="2" type="text">
<label> Places required</label>
<p class="btn update">Update</p>
<input name="product_id" value="2" class="product_id" type="hidden">
<p class="btn remove">Remove from basket</p>
</div>
<a href="/product//"><img src="http://dummyimage.com/100x100/333/eee" alt="" class="border-thick shadow"></a>
<div class="left">
<h5>Title</h5>
<select name="courses_details_id">
<option value="">Select date/venue...</option>
<option value="6">10 Oct 2011 - Chicago, USA</option>
<option value="4">13 Oct 2011 - Hastings</option>
<option value="2">18 Nov 2011 - Paris, France</option>
</select>
<br>
<p class="price"><span class="small">From</span> £77.88</p>
</div>
And I simply want to get the value for product_id, so this makes sense:
$('#basket li form select[name=courses_details_id]').change( function(){
$(this).parent().parent().children("input[name$=product_id]").val();
});
but it returns a value of undefined
Upvotes: 0
Views: 90
Reputation: 4848
Simplify your markup. Make you select element look like this
<select name="course_details_id" id="course_details"/>
Then to get the value its a simple matter of:
$("#course_details").change(function() {
var product = $(this).val();
});
Upvotes: 0
Reputation: 13756
You are missing quotation marks in your selector, it should be like this
$('input[name$="product_id"]')
Upvotes: 0