PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<script type="text/javascript">
<!--
function confirmation() {
var answer = confirm("Are you sure you want to delete this record?")
if (answer){
window.location = "delete.php?table_name=$entry_type&entry_no=$read[entry_no]";
}
}
//-->
</script>
First of all javascript can't use php variables, here's an example of passing a variable from php to javascript, you should be able to figure the rest out:
function confirmation(entry_type, entry_no) {
var answer = confirm("Are you sure you want to delete this record?")
if (answer){
window.location = "delete.php?table_name=" + entry_type + "&entry_no=" + entry_no;
}
}
It still doesn't work, the popup window is not created. Where am I making a mistake?
jshpro2 wrote:First of all javascript can't use php variables, here's an example of passing a variable from php to javascript, you should be able to figure the rest out:
the reason I escaped those single quotes in my example was because my echo() was using single quotes so the variables wouldn't be expanded, just for informational purposes so when your variables were NULL in your script you would at least see javascript was doing it's job.
Now this 'mistake' is questionable:
javascript:void(0)
: should be a colon, I don't know if the forum put that there for you (it replaced my colon) or if you actually copy pasted the 058 from my code.
the reason I escaped those single quotes in my example was because my echo() was using single quotes so the variables wouldn't be expanded, just for informational purposes so when your variables were NULL in your script you would at least see javascript was doing it's job.
Now this 'mistake' is questionable:
javascript:void(0)
: should be a colon, I don't know if the forum put that there for you (it replaced my colon) or if you actually copy pasted the 058 from my code.
: is really a colon I don't know how the forum puts it that way.
I changed my code as you said and I also concatenated it. Now the popup window appears when I click the link but nothing is done as I click OK button.
I'm not familiar with js, so is that code is true if I want to move to another file (delete.php)
Burrito wrote:you might try changing your href attribute to "javascript:confirmation('blah','bling')"
I like to use the void "trick" to hide javascript function names from the status bar in the browser during hovering on a link.. just a personal preference and I haven't really come across any compatability issues with it yet.