I am connecting this javascript to server code, but I am having trouble selecting the right element. Regardless of what button I select, the video_id always ends up being the first one (in this case "bbc"). How do I change the javascript/jquery to select the right value for video_id depending on the button selected?
<script type="text/javascript">
$(document).ready(function() {
$(".removebutton").submit(function(event){
event.preventDefault();
$.ajax({
type:"POST",
url:"/munch_video/",
data: {
'video_id': $('#video_id').val(), // from form
'playlist': $('.playlist').val(), // from form
'add_remove': $('.add_remove').val(), // from form
},
success: function(message){
alert(message);
$('.span8').html(message);
}
});
return false;
});
});
</script>
<form method='post' action = '/munch_video/ ' class = 'removebutton'>{% csrf_token %}
<input type="hidden" value="Channel" class = "playlist"/>
<input type="hidden" value="bbc" id = "video_id"/>
<input type="hidden" value="remove_video" class = "add_remove"/>
<input type='submit' class="btn btn-danger" value='Remove from plate'/>
</form>
<form method='post' action = '/munch_video/ ' class = 'removebutton'>{% csrf_token %}
<input type="hidden" value="Channel" class = "playlist"/>
<input type="hidden" value="toyota" id = "video_id"/>
<input type="hidden" value="remove_video" class = "add_remove"/>
<input type='submit' class="btn btn-danger" value='Remove from plate'/>
</form>
<form method='post' action = '/munch_video/ ' class = 'removebutton'>{% csrf_token %}
<input type="hidden" value="Channel" class = "playlist"/>
<input type="hidden" value="gm" id = "video_id"/>
<input type="hidden" value="remove_video" class = "add_remove"/>
<input type='submit' class="btn btn-danger" value='Remove from plate'/>
</form>
can be multiple buttons, each with a different video_id value