?
Solved

calling java script with href from wihin  PHP?

Posted on 2012-04-04
9
Medium Priority
?
187 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
WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

 
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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 count occurrences of each item in an array.
Suggested Courses

770 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