Dschehuti Nefer Dschehuti Nefer - 4 months ago 8
HTML Question

Returning value of an <input> using a button

I have seen a couple of similar questions, but everything I've attempted so far has failed and I hope someone can make it clearer what noob-error I'm having here.
Thing is I have a rather large automatically generated number of tables and now I need a simple JQuery to get the hidden uniqe ID of each row and use them as an input for an Ajax script. And here I'm frustrated because I am not even able to get that stupid number...
Well, right now the row contains the ID and a button to get it like this:

<div class="pull-right">
<input type="hidden" class="thisSeriesID" th:value="${appointment.seriesID}">
<button class="btn btn-default entryChecker"><span class="glyphicon glyphicon-refresh"></span></button>
</div>


Now I'm currently using this JQuery to get the ID and test whether it worked or not. It is just the latest of many attempts, but just as useless:

<script type="text/javascript">
$(function(){
$(".entryChecker").click(function(){
var x = $(this).prev().val();
document.getElementById("demo").innerHTML = x.toString();
});
}
);
</script>


My aim is of course that if I push any of the buttons, I get the respective ID in this line:

<p id="demo"></p>


But as you people who are more clever than me might have guessed: Nothing happens.
Can anyone give me a hint where I messed up?

Answer
<html>
<head>
    <script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script>


     $( document ).ready(function() {
         $(".entryChecker").click(function(){
            var myvalue = $(this).prev('.thisSeriesID').val();
            console.log(myvalue);
            document.getElementById("demo").innerHTML = myvalue;
            });
                 });


    </script>
</head>
<body>
    <div class="pull-right">
     <input type="hidden" class="thisSeriesID"  value="5" />
     <button class="btn btn-default entryChecker"> Check<span class="glyphicon glyphicon-refresh"></span></button>
</div>
    <div id="demo"> </div>
</body>
</html>