Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-29-2013, 09:03 AM   PM User | #1
Ndogg
Regular Coder

 
Join Date: Jun 2009
Posts: 272
Thanks: 76
Thanked 2 Times in 2 Posts
Ndogg can only hope to improve
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..
Ndogg is offline   Reply With Quote
Old 01-29-2013, 02:24 PM   PM User | #2
m2244
Regular Coder

 
Join Date: Jun 2012
Posts: 127
Thanks: 1
Thanked 1 Time in 1 Post
m2244 is an unknown quantity at this point
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.
m2244 is offline   Reply With Quote
Users who have thanked m2244 for this post:
Ndogg (01-30-2013)
Old 01-29-2013, 02:48 PM   PM User | #3
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,362
Thanks: 18
Thanked 347 Times in 346 Posts
sunfighter is on a distinguished road
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>
sunfighter is offline   Reply With Quote
Users who have thanked sunfighter for this post:
Ndogg (01-30-2013)
Old 01-30-2013, 08:03 AM   PM User | #4
Ndogg
Regular Coder

 
Join Date: Jun 2009
Posts: 272
Thanks: 76
Thanked 2 Times in 2 Posts
Ndogg can only hope to improve
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
Ndogg is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:24 AM.


Advertisement
Log in to turn off these ads.