How do I select the right element using javascript?

ucenik1

New Member
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?\[code\] <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="http://stackoverflow.com/questions/13716231/Channel" class = "playlist"/> <input type="hidden" value="http://stackoverflow.com/questions/13716231/bbc" id = "video_id"/> <input type="hidden" value="http://stackoverflow.com/questions/13716231/remove_video" class = "add_remove"/> <input type='submit' class="btn btn-danger" value='http://stackoverflow.com/questions/13716231/Remove from plate'/> </form> <form method='post' action = '/munch_video/ ' class = 'removebutton'>{% csrf_token %} <input type="hidden" value="http://stackoverflow.com/questions/13716231/Channel" class = "playlist"/> <input type="hidden" value="http://stackoverflow.com/questions/13716231/toyota" id = "video_id"/> <input type="hidden" value="http://stackoverflow.com/questions/13716231/remove_video" class = "add_remove"/> <input type='submit' class="btn btn-danger" value='http://stackoverflow.com/questions/13716231/Remove from plate'/> </form> <form method='post' action = '/munch_video/ ' class = 'removebutton'>{% csrf_token %} <input type="hidden" value="http://stackoverflow.com/questions/13716231/Channel" class = "playlist"/> <input type="hidden" value="http://stackoverflow.com/questions/13716231/gm" id = "video_id"/> <input type="hidden" value="http://stackoverflow.com/questions/13716231/remove_video" class = "add_remove"/> <input type='submit' class="btn btn-danger" value='http://stackoverflow.com/questions/13716231/Remove from plate'/> </form> can be multiple buttons, each with a different video_id value\[/code\]
 
Back
Top