Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

Java Script not working in PHP

Links for php scripts

Moderators: macek, egami, gesf

Java Script not working in PHP

Postby shnkrsv » Thu May 31, 2012 1:45 am

Am trying to use this very simple code for delete a record from my db. But before that i have to prompt the user for confirmation to delete or not. So am using this simple script in php, but its not working... Please some one help.

Code: Select all
<?php
Print "<td><a href='full_delete.php?id=".$info['id']."&article_name=".$info['name']."&table_name=$table_name' onClick='confirm('Are you sure you want to delete?');'><img src='../images/deletebutton.png' id='delbtn' /></a></td>";


On clicking the link, it just redirecting without the confirmation msg box.

I dont have issue in deleting, the confirmation msg box not prompting. :(

Please someone try to solve my simple question..
User avatar
shnkrsv
New php-forum User
New php-forum User
 
Posts: 27
Joined: Sun Oct 30, 2011 10:48 pm
Location: Coimbatore

Re: Java Script not working in PHP

Postby Nullsig » Thu May 31, 2012 4:53 am

You should remove the href and have the onClick action handle all of the redirection.
Code: Select all
   
<?php
    Print "<td><a href='#' onClick=\"confirmDelete('" . $info['id'] . "','" . $info['name'] . "','" . $table_name . "')\"><img src='../images/deletebutton.png' id='delbtn' /></a></td>";


So that is a lot of change. I am not calling a confirmDelete JavaScript function that takes 3 variables: id, name, table_name. I am no longer supplying a href for the anchor tag.

Now to show you what the confirmDelete function will look like.
Code: Select all
<script type='text/javascript'>
      function confirmDelete(id,name,table_name){
              var r=confirm("Are you sure you want to delete?");
              if (r==true){
                    window.location = "full_delete.php?id=" + id  + "&article_name=" + name + "&table_name=" + table_name;
              }else{
                    return false;
              }
      }
</script>


This issues the prompt and when the response is "true" the page will be redirected accordingly.
User avatar
Nullsig
php-forum Fan User
php-forum Fan User
 
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Re: Java Script not working in PHP

Postby shnkrsv » Thu May 31, 2012 5:20 am

Thank you Nullsig, but i found a easy way to do that...

This code works good... :) :)

Code: Select all
?>
<td>
<a href='full_delete.php?id=<?php echo $info['id'] ?>&article_name=<?php echo $info['name'] ?>&table_name=<?php echo $table_name ?>&index_img=<?php echo $info['img'] ?>&url=<?php echo $info['url'] ?>' onClick="return confirm('You are about to delete <?php echo $info['name'] ?> and its Gallery. Are you sure you want to delete?')">
<img src='../images/deletebutton.png' id='delbtn' /></a></td> <?php


Really thank you for your interest to solve my problem...
User avatar
shnkrsv
New php-forum User
New php-forum User
 
Posts: 27
Joined: Sun Oct 30, 2011 10:48 pm
Location: Coimbatore


Return to PHP Scripts

Who is online

Users browsing this forum: Google Feedfetcher and 0 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.