popup message before deleting data - php

I'm trying to put popup message in this code before user delete data. Here is my code.
while ($test = mysql_fetch_array($result))
{
$id = $test['FailID'];
echo "<tr align='center'>";
echo"<td><font color='black'>" .$test['FailID']."</font></td>";
echo"<td><font color='black'>" .$test['TajukFail']."</font></td>";
echo"<td><font color='black'>". $test['JilidFail']. "</font></td>";
echo"<td><font color='black'>". $test['StatusFail']. "</font></td>";
echo"<td> <a href ='daftarkemaskini.php?FailID=$id'>Edit</a>";
echo"<td> <a href ='padamfail.php?FailID=$id'><center>Delete</center></a>";
echo "</tr>";
}
but when I put it in there it doesnt work at all.
echo"<td> <a href ='padamfail.php?FailID=$id' onClick="return confirm('are you sure you want to delete??');"><center>Delete</center></";>"
Can anyone help me on this?

You need to escape the double quotes. Your code also had another syntax error at the end.
echo "<td> <a href='padamfail.php?FailID=$id' onClick=\"return
confirm('are you sure you want to delete??');\"><center>Delete</center></a>";

You are putting javascript onclick code inside a double quote, which is being used to terminate the echo. Escape the double quotes:
echo"<td> <center>Delete</center>"

You can try this--
echo "<td> <a href ='padamfail.php?FailID=$id' onClick=return confirm('are you sure you want to delete??');><center>Delete</center></;>";

Try to escape the string:
echo "<td> <a href ='padamfail.php?FailID=$id' onClick=\"return confirm('are you sure you want to delete??');\"><center>Delete</center></";>"

<div class="third">
<input type="button" value="Remove" class="remve" name="<?php echo $row['choice_id']; ?>" onClick="deleteImage(<?php echo $row['choice_id']; ?>)"style="cursor:pointer;">
</div>
<script type="text/javascript">
function deleteImage(x){
var conf = confirm("Are you sure you want to delete this choice?");
if(conf == true){
window.location = "addnewentry/choiceRemove.php?id="+x;
}
}
</script>

Please the change the line
echo"<td> <a href ='padamfail.php?FailID=$id' onClick="return confirm('are you sure you want to delete??');"><center>Delete</center></";>"
to
echo "<td> <a href ='padamfail.php?FailID=$id' onClick='return confirm('are you sure you want to delete??');' ><center>Delete</center></a>";

echo"<td><a href='delete.php?id={$row['id']}' onclick='return confirm_alert(this);' >Delete</a></td>";
**you should try this code ,it will definitely work **
=
<script>
//alert on delete
function confirm_alert(node) {
return confirm("You are about to permanently delete a product. Click OK to continue or CANCEL to quit.");
}
</script>
<script>
//alert on delete
function confirm_alert(node) {
return confirm("You are about to permanently delete a product. Click OK to continue or CANCEL to quit.");
}
</script>
hoping this will help you

Related

How to echo a href links with onclick alert php

Problem
When i click this link its alert won't open what should I do ?
My Code
echo "<td><a href='#' onClick='alert('Not an Enumerator!')'>Location</a></td>";
You have to escape quotes \' when necessary, try this:
echo '<td>Location</td>';
Try By Following Example.
<a href="#" onClick='alert("Not an Enumerator!")'>Location</a>
Don't Use Single quote inside alert
Try below example you can do both alert and onclick or either based on return type of function called on click.
<?php
echo "<td><a href='test.php' onclick='return test_click();'>Location</a></td>";
?>
<script type="text/javascript">
function test_click(event){
alert("Inside this function");
return true;
}
</script>

Php variable need to get in jquery popup

this is my html table part.. popup will open when i click on my update button.
<?php
{
include("config/dbconfig.php");
$res = mysql_query("SELECT * FROM tbl_company");
echo"<table>";
while($row=mysql_fetch_array($res))
{
$s= $row['company_id'];
$r= $row['company_name'];
$a= $row['head_office_city'];
echo"<tr><td>".$r."</td><td>".$a."</td>
<td><img title='update details' alt=\"Delete\" class='del' src='images/update.png'/> </td>
<td><img title='make company inactive' alt=\"Delete\" class='del' src='images/delete.png'/> </td></tr>";
}
echo"</table>";
}
?>
<div id="toPopup">
<div class="close"></div>
<span class="ecs_tooltip">Press Esc to close <span class="arrow"></span></span>
<div id="popup_content"> <!--your content start-->
this is the kind of popup that i'm using
in this popup rest part of editing company details should be done. for that I need to get company_id.
How I get this $company_id value to popup page?
You can write it like you PHP code like this
<td>
<a href=\"#\" class=\"topopup\" id=\"update_comp\" onclick=\"return openPoup('".$row['company_id']."')\" \">
<img title='update details' alt=\"Delete\" class='del' src='images/update.png'/>
</a>
</td>
and in JavaScript you can write
<script type="text/javascript">
function openPoup(companyId){
window.open('/editcomapny.php?comapnyId='+companyId);
}
</script>
<td><a href=\"#\" class=\"topopup\" id=\"update_comp\" onClick=\"return callYourPopup(".$row['company_id'].");\">
<script type="text/javascript">
function callYourPopup(id) {
alert("Do something with " + id);
return false;
}
</script>

Need to get id attribute

I have this php code to populate with links:
foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $result)
{
if($result['tip']=='1')
{
$camere=" - ".$result['camere'];
}
else
{
$camere="";
}
$view[]="
<tr>
<td>".$result['id_anunt']."</td>
<td>".$result['den_tranzactie']."</td>
<td>".$result['den_prop'].$camere."</td>
<td>".$result['judet']." ".$result['oras']." ".$result['zona']."</td>
<td><a href='#' id='".$result['id_anunt']."' onclick='view();'>View</a> <a href='#' id='".$result['id_anunt']."'>Edit</a> <a href='#' id='".$result['id_anunt']."'>Arhivare</a> <a href='#' id='".$result['id_anunt']."'>special</a></td>
</tr>";
}
I need to get the id attribute for "View" link on click it with this function:
function view()
{
alert ($(this).prop('id'));
}
but I receive this: "object HTMLinputelemnt".
How can I get the id?
Thanks a lot.
Put a Class on your link.
Eg:
<a href="#" class="viewLink" id="....
Then in jquery:
$(".viewLink").click(function() {
var id = $(this).attr('id');
alert(id);
});
Modify your
onclick='view();'
to
onclick='view(this);'
And the view function as
function view(link)
{
alert ($(link).attr('id'));
}
use
$view[]="
<tr>
<td>".$result['id_anunt']."</td>
<td>".$result['den_tranzactie']."</td>
<td>".$result['den_prop'].$camere."</td>
<td>".$result['judet']." ".$result['oras']." ".$result['zona']."</td>
<td><a href='#' id='".$result['id_anunt']."' onclick='return view(this);'>View</a> <a href='#' id='".$result['id_anunt']."'>Edit</a> <a href='#' id='".$result['id_anunt']."'>Arhivare</a> <a href='#' id='".$result['id_anunt']."'>special</a></td>
</tr>";
Javascript
function view(element){
alert (element.id);
return false;
}
OR
alert ($(link).attr('id'));
Make sure you pass the link object as a parameter to view(), like this: onclick='view(this);'
Then in pure javascript:
function view(el)
{
alert(el.id);
}
"Don't use a canon to kill a mosquito". -- Confucius

Delete Confirmation when click on link

I have this code inside a while loop for fetching data from the database. I want to show a confirmation popup when the Delete link is clicked.
echo "<td><a href='delete.php?id=" . $row['serial_no'] . "'>Delete</a></td>";
How can this be done?
Try out confirm function from JavaScript, learn jQuery as fast as possible and try to seperate javascript from html ;).
http://www.w3schools.com/jsref/met_win_confirm.asp
<td>
<a href="delete.php?id=<?php echo $row['serial_no'] ?>" id="a_id">
Delete
</a>
</td>
<script type="text/javascript">
$(function() {
$('td a#a_id').click(function() {
return confirm("Are You sure that You want to delete this?");
});
});
</script>
add onClick attribute for anchor link and call the function on it. Or simply show confirm.
<a onClick = "confirm ('Are You Sure?')"
Complete Example
function disp_confirm()
{
var r=confirm("Press a button!")
if (r==true)
{
alert("You pressed OK!")
}
else
{
alert("You pressed Cancel!")
}
}
<a onclick="disp_confirm()"
try this
function DeleteClick(serial_no)
{
if(confirm('Are you sure to delete ' + serial_no + '?'))
{
alert('Data deleted');
return true;
}
return false;
}
echo "<td><a href='delete.php?id=" . $row['serial_no'] . "' onclick="return
DeleteClick(\''. $row['serial_no'].'\')">Delete</a></td>";
echo "<td>Delete</td>";
try this code,hope it will work-
<td>
<a href="#" onclick="conf("delete.php?id=".<?php echo $row['serial_no']; ?>.")">
Delete
</a>
</td>
<script type="text/javascript">
function conf(str) {
if(confirm("Your Message") == true){ location.replace(str);}
}
</script>
and in the delete.php page-just grab the id from url and run the delete query.

javascript onclick delete not working

Why is it that my onClick won't work?
When I click I get an error message like this:
syntax error : identifier starts immediately after numeric literal
It will not determine the ID from the database, the database ID is varchar(50).
<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick='delete_Affiliate(".$row['affiliateid'].")'></a>
<script type="text/javascript">
function delete_Affiliate(id){
alert(id);
}
</script>
Try this:
delete_Affiliate(" <?php echo $row['affiliateid']; ?>")
That is, you need to echo the value from PHP.
Try this
<script type="text/javascript">
function delete_Affiliate(id){
alert(id);
}
Can you please post your PHP script ?
You should have something like :
<?php
echo "<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick='delete_Affiliate(\"".$row['affiliateid']."\");return false;'></a>
<script type='text/javascript'>
function delete_Affiliate(id){
alert(id);
}
</script>";
?>
try this :
<?php
echo "<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick='delete_Affiliate(".$row['affiliateid'].");'></a>";
?>
or this :
<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick='delete_Affiliate("<?php echo $row['affiliateid'] ?>");'></a>
you have to add php tag and echo statement between your anchor tag like this
<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick='delete_Affiliate("<?php echo $row['affiliateid']; ?>")'></a>
you didn't add this
<?php echo $row['affiliateid']; ?>
in your anchor tag so just add it and check it out.
I hope it will help you
Try this
delete_Affiliate(<?php echo $row['affiliateid']; ?>);
there may be issue on this line
<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick='delete_Affiliate(".$row['affiliateid'].")'></a>
it should be
<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick='delete_Affiliate("<?php echo $row['affiliateid']; ?>")'></a>
Use this code, hope it will work

Categories