简体   繁体   中英

pass id to jquery modal form

i have following table where i am showing data from database. when i click edit button a dialog appear, there i need to show data in text boxes from db. but for getting data from db i need player_id in modal from.

<td><?php echo $player_id ?></td>
<td><?php echo $name; ?></td>
<td><?php echo $details; ?></td>
<td><button id="update_user">Edit</button></td>

so here i want to pass player_id to jquery modal form, where i can get data from db on the base of player_id for that specific player and show in text boxes and then again update to db.

<div id="update-form" title="Update Employee">

    <label for="id">ID</label>
    <input type="text" name="player_id" id="player_id" value="$player_id" />
    <label for="name">Name</label>
    <input type="text" name="name" id="name" value="$name"/>
          <label for="details">Details</label>
    <input type="text" name="details" id="details" value="$details"/>

i want to pass $player_id variable to jquery Modal form. that's all.

try something like this:

<td><?php echo $player_id ?></td>
<td><?php echo $name; ?></td>
<td><?php echo $details; ?></td>
<td>
    <button class="update_user" data-payer_id="<?php echo $player_id ?>">Edit</button>
</td>

<script>
$(".update_user").click(function(){
    var player_id = $(this).attr('data-payer_id');
    $("#update-form").find("#player_id").val(player_id);
    $("#update-form").dialog("open");
});
</script>

PS: player_id should be a hidden field in the dialog form unless it is editable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM