Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2009
    Posts
    278
    Thanks
    78
    Thanked 2 Times in 2 Posts

    OnClick Popup Issue

    Code:
    <?php
    $log = 'Admin';
    ?>
    
    <a onclick="Delete_All(<?php echo $log; ?>)">
    
    <script>
    function Delete_All(log) {
    	var r=confirm("Are you sure you want to delete every Log?");
    	
    	if (r==true){
    		window.location.assign("ACP.php?page=Maintenance&sub="+log+"_Log&action=Delete_All");
    	}
    }
    </script>


    So, without <?php echo $log; ?> the script works normally. I don't see why, and it doesn't even work if I replace the <?php echo $log; ?> with 'Admin'. What am I doing wrong?
    Last edited by Ndogg; 01-30-2013 at 08:13 AM.

  • #2
    Regular Coder
    Join Date
    Jun 2012
    Posts
    137
    Thanks
    1
    Thanked 1 Time in 1 Post
    Have you tried to simply get the echo to work?

    Code:
    <a onclick=<?php echo $log; ?>>
    and then step forward from there until it doesn't work. Good luck.

  • Users who have thanked m2244 for this post:

    Ndogg (01-30-2013)

  • #3
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,177
    Thanks
    23
    Thanked 601 Times in 600 Posts
    When passing variables into a function, they must be a string or in quotes. This looks like a string. but it's not. You are missing a close tag also.
    The line S/B:
    Code:
    <a onclick="Delete_All(<?php echo "'".$log."'"; ?>)">Click here to delete stuff</a>

  • Users who have thanked sunfighter for this post:

    Ndogg (01-30-2013)

  • #4
    Regular Coder
    Join Date
    Jun 2009
    Posts
    278
    Thanks
    78
    Thanked 2 Times in 2 Posts
    EDIT:

    @sunfighter
    After testing your solution, it got me to a point which showed that the problem is in a different part of my script. I added "+log" to the popup and it displayed Admin. So the issue was somewhere else... Thank you


    Quote Originally Posted by m2244 View Post
    Have you tried to simply get the echo to work?

    Code:
    <a onclick=<?php echo $log; ?>>
    and then step forward from there until it doesn't work. Good luck.
    Thanks for the suggestions, I have checked the echo and moved through the steps to see if I could figure it out. But all I could do was narrow down where the issue was... I think.

    Quote Originally Posted by sunfighter View Post
    When passing variables into a function, they must be a string or in quotes. This looks like a string. but it's not. You are missing a close tag also.
    The line S/B:
    Code:
    <a onclick="Delete_All(<?php echo "'".$log."'"; ?>)">Click here to delete stuff</a>
    In another part that is just "Delete", I also have <?php echo $row['id']; ?> which works fine. It is actually an integer but it is passed the same way, so that might mean your solution isn't correct here? I'm not sure, but adding the quotes like you said doesn't work for me. Although, now the script actually runs and creates a popup, but the $log doesn't get sent. So when redirecting it goes to the incorrect page.
    Last edited by Ndogg; 01-30-2013 at 08:14 AM. Reason: Possibly Found Solution


  •  

    Posting Permissions

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