SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist FCC's Avatar
    Join Date
    May 2006
    Posts
    417
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Undefined Problem with PHP and Javascript

    Hi all,

    I am working on this script to call a Javascript confirmation box with PHP, but I keep getting an error. This is my code for the PHP part which calls the confirmDelete function:

    Code:
    <a href=\"#\" onclick=\"confirmDelete($user_name)\"><img src='Images/userDelete.gif' alt='Delete User' /></a>
    And the actually javascript function
    Code:
    function confirmDelete(user)
    {
    	var where_to = confirm("Are you sure you want to delete this user");
    	if (where_to== true)
     	   window.location="userDelete.php?username=user";
    }
    The problem is that javascript gives me this 'user_name' is undefinded error....what is the problem here?

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need quotes around the user name.
    Code:
    <a href=\"#\" onclick=\"confirmDelete('$user_name')\">
    If there is a complaint about 'user_name', it seems as if your code is not run through the PHP parser.
    Birnam wood is come to Dunsinane


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •