1

How do you pass two values using a button? My values are value="" data-value="CPS210-CompSci-I (4)".

<button type="button" data-toggle="modal" data-target="#myModal1" class="btn btn-warning btn-md" name="grade" value="<?php echo " $cs1 "; ?>" data-value="CPS210-CompSci-I (4)">
  <span class="glyphicon glyphicon-education "></span> Grade
</button>
<script>
  $('button[name="grade"]').click(function() {
    var grade = $(this).val();
    //var cs=$(this).
    $('#grade').html("<h4> Grade recived " + grade + "</h4>");
    $('#cs').html("<h4>" + cs + "</h4>");
  });
</script>
<div class="modal-body">
  <p id="grade"></p>
  <p id="cs"></p>
</div>

1 Answer 1

2

You can use the getter version of .data() to access your required data-attribute,

$('button[name="grade"]').click(function() {
  var grade = $(this).val();
  var cs = $(this).data("value"); // .data("dataAttributeName")
  $('#grade').html("<h4> Grade recived " + grade + "</h4>");
  $('#cs').html("<h4>" + cs + "</h4>");
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.