javascript - Get value from button in while loop -


i've got while loop multiple buttons, this:

<button onclick="confirmdelete()" value="<?php echo $game['id'];?>" name="deletebutton">delete </button>  

it followed following confirm message:

<script> function confirmdelete() {  var r = confirm(" **here want id start with** "); if (r == true) {     // delete } else {     // cancel } } </script> 

each button has own value, want value in javascript when click on button. tried multiple things cant make work.

edit:

if can tell me better/easier way this, you're welcome tell me

use function this argument, i.e.:

<button onclick="confirmdelete(this)" id="mybutton" value="someid" name="deletebutton">delete </button>  <script> function confirmdelete(elem) { var r = confirm(" **here want id start with** "); var thevalue = elem.value; //someid var theid    = elem.id; //mybutton if (thevalue == "true") {     alert("true") } else {     alert("false") } } </script> 

live demo:
http://codepen.io/anon/pen/qyzgqo


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -