can anyone heLp me

i need to send an id to a page through a javascript function but it wont work
he can't read the variable

 function confirm_delete() {    
var answer=confirm("Are You Sure You Want to Delete ?");
   if(answer==true)
     { 
        window.location="delete.php?id=$id"; 
      // alert(" Title Deleted");
     }
 else 
        return false ;  
        }

Recommended Answers

All 2 Replies

Member Avatar for langsor

Correct, javascript doesn't know PHP.

Either grab the ID via javascript

window.location="delete.php?id=" + myElement.id;

or write it in with a full PHP script

window.location="delete.php?id=<? echo $id ?>";

Not seeing the rest of your script I don't know where you plan on getting the $id value ...

Hope this helps

hello try this code will work perfectly:

function confirm_delete(x) {
var answer=confirm("Are You Sure You Want to Delete ?");
if(answer==true)
{ 
		window.location.href="delete.php?id="+x;
		} 
		return;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.