Solved

calling java script with href from wihin  PHP?

Posted on 2012-04-04
9
178 Views
Last Modified: 2012-04-26
Hi, I have a php statement as follows:

 $output.= "<td height=\"50;\"style=\"background-color:$color; vertical-align: top\" name=\"$cellnumber\">$date</td>\n";

I need to add the following href statement to this td tag;
<A HREF=close.html    onClick=return popup(this, '$cellnumber')\">

Can someone let me know how this can be done? Thanks.

A
0
Comment
Question by:aej1973
  • 6
  • 3
9 Comments
 

Author Comment

by:aej1973
ID: 37808778
What I have now is:

 $output.= "<td height=\"50;\"style=\"background-color:$color; vertical-align: top\" name=\"$cellnumber\"><A HREF=close.html
   onClick=return popup(this, '$cellnumber')\">$date</td>\n";

But when I do this close.html opens as a new window and my js is not called. My js is as follows:

$html = <<<ENDHTML
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Planner</title>
<SCRIPT TYPE="text/javascript">
<!--
function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=400,height=200,scrollbars=yes');
return false;
}
//-->
</SCRIPT>
</head>

<body>
ENDHTML;

echo '<div  align="center">';

Thanks for the help.

A
0
 
LVL 7

Expert Comment

by:designatedinitializer
ID: 37808920
If you want that link to work, then this:

$output.= "<td height=\"50;\"style=\"background-color:$color; vertical-align: top\" name=\"$cellnumber\"><A HREF=close.html
   onClick=return popup(this, '$cellnumber')\">$date</td>\n";

should be this:

$output.= "<td height=\"50;\"style=\"background-color:$color; vertical-align: top\" name=\"$cellnumber\"><A HREF=\"close.html\" onClick=\"return popup(this, '$cellnumber')\">$date</td>\n";

and, in order to open on the same window, this:

window.open(href, windowname, 'width=400,height=200,scrollbars=yes');

should be this:

window.open(href, '_self', 'width=400,height=200,scrollbars=yes');
0
 

Author Comment

by:aej1973
ID: 37808937
Hi designatedinitializer: I tried the following script ;


                $output.= "<td height=\"50;\"style=\"background-color:$color; vertical-align: top\" name=\"$cellnumber\"><A HREF=\"close.html\" onClick=\"return popup(this, '$cellnumber')\">$date</td>\n";

but I do not get close.html to open as a pop up, it is opening up as a new window. I am using firefox. Any suggestions? Thanks.

A
0
 
LVL 7

Expert Comment

by:designatedinitializer
ID: 37808984
You might want to change the href in the link to:

... href=\"#\"

what is happening is that link is effective and so the onClick doesn't get called
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:aej1973
ID: 37809168
This is what I have now:

$output.= "<td height=\"50;\"style=\"background-color:$color; vertical-align: top\" name=\"$cellnumber\"><A href=\"#\"close.html\" onClick=\"return popup(this, '$cellnumber')\">$date</td>\n";

Does not seem to work. The only thing that happens is my url changes from:

http://localhost:8080/cs/module_patient/cellColor.php

to

http://localhost:8080/cs/module_patient/cellColor.php#

any suggestions? Thanks for the help.
0
 

Author Comment

by:aej1973
ID: 37809290
Designatedinitializer, any suggestions? sorry to bug you...for what ever reason it does not seem to want to work.

Thanks,
A
0
 

Accepted Solution

by:
aej1973 earned 0 total points
ID: 37809329
it is working now. Just moved the following code outside the php tags;

$html = <<<ENDHTML
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Planner</title>
<SCRIPT TYPE="text/javascript">
<!--
function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=400,height=200,scrollbars=yes');
return false;
}
//-->
</SCRIPT>
</head>

<body>

Thanks,
A
0
 
LVL 7

Expert Comment

by:designatedinitializer
ID: 37810165
Glad you made it!
0
 

Author Closing Comment

by:aej1973
ID: 37896106
Thank you for the help but I had to figure out the solution.

A
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now