Solved

calling java script with href from wihin  PHP?

Posted on 2012-04-04
9
177 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
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…

746 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

14 Experts available now in Live!

Get 1:1 Help Now