Solved

calling java script with href from wihin  PHP?

Posted on 2012-04-04
9
179 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
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
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 look for a specific file type in a local or remote server directory using PHP.

803 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