javascript - How to open a pop-up window based on selected id using radio button and how to pass that selected id to pop-up window, using php,MySQL

108

I am using mysql_fetch_array() to fetch data from MYSQL and I am displaying that data in the form of HTML table using PHP. HTML Table's first column is primary key of data base table. I added radio button to it while displaying fetched result. I have UPDATE and DELETE buttons on top of HTML table. If I select a radio button and click UPDATE/DELETE, a pop-up window should appear to display that selected row values. For this I think I need to pass selected row id/key to pop-up window. If any one know how to achieve it, let me know!

<?php
    while($rows=mysql_fetch_array($result))
    {

 ?>
 <table>
  <tr>
   <td><? echo $rows['ID']; ?></td>
   <td><input type="radio" name="" value=""><? echo $rows['Name']; ?></td>
   <td><? echo $rows['Surname']; ?></td>
   <td><? echo $rows['Number']; ?></td>
  </tr>
</table>
  <?php
 }
?>

Thanks In Advance!!!

368

Answer

Solution:

please see this code

 <td><input type="radio" name="" value="" onclick="alert("<?php echo "you have selected ".$rows['ID']." want to update or delete??"; ?>")"><? echo $rows['Name']; ?></td>

hope it will usefulllll

47

Answer

Solution:

You can perform UPDATE and DELETE operation by using below code.

<table>
  <tr id="row_1" data-idval="1"><td>1</td>
    <td>XYZZZZ</td>
    <td>PQR</td>
    <td>----</td>
    <td><span >UPDATE</span></td>
    <td><span >DELETE</span></td>
  </tr>  
  <tr id="row_2" data-idval="2"><td>2</td>
    <td>XYZZZZ</td>
    <td>PQR</td>
    <td>----</td>
    <td><span >UPDATE</span></td>
    <td><span >DELETE</span></td>
  </tr> 
    <tr id="row_3" data-idval="3"><td>3</td>
    <td>XYZZZZ</td>
    <td>PQR</td>
    <td>----</td>
    <td><span >UPDATE</span></td>
    <td><span >DELETE</span></td>
  </tr> 
</table>

Javascript:-

<script type="text/javscript">
function yesnodialog(button1, button2, element){
  var btns = {};
  btns[button1] = function(){ 
      var id_val =  element.parents('tr').data('idval');
      alert(id_val);
      //write here update code using ajax here
      $(this).dialog("close");
  };
  btns[button2] = function(){ 
      // Do nothing
      $(this).dialog("close");
  };
  $("<div></div>").dialog({
    autoOpen: true,
    title: 'Condition',
    modal:true,
    buttons:btns
  });
}
$('.update').click(function(){
    yesnodialog('Yes', 'No', $(this));
})


</script> 

Same you can do forDELETE as well.

See live demo here

People are also looking for solutions to the problem: Random whitespace in a PHP page (the client received page, but not the client-received source-code), but only when I use an include()

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.