Solved

calling java script with href from wihin  PHP?

Posted on 2012-04-04
9
183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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
 

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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

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.  …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

688 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