Jump to content

[SOLVED] Question about Javascript inside php


mediabob

Recommended Posts

I am trying to make a pop up window that open when a person click a link, I use this same code on other pages but in this case the links are conditional based on the users member level so they are stored in a variable via a switch case statement.

 

So my question is, how can I call the javascript pop up function INSIDE the php?

 

normally I would use

 

<a href="javascript:example('URL');">LINK</a>

 

but since the link is inside a case statement and I had to use " on the outside I switched the inside  to just '

and this resulted in the link cutting off at the first ' inside the bracket so when you hover over it you get

 

javascript:example(

 

as the URL

 

if I remove the inside ' '  around the URL comepletely to make the code

 

 

<a href='javascript:example(URL);'>LINK</a>

 

the URL appears correctly when you hover the link but nothing happens when you click it.

 

Any ideas?

 

Thanks

Will this not work  ???

 

echo "<a href=\"javascript:example('URL');\">LINK[/url]";

 

You can also jump in and out of php

(im not use to using case statements)

<?php
$variable = 1;
if $variable ==1)
{
?>
<a href='javascript:example(URL);'>LINK[/url]
<?php
}
else
{
?>
<a href='javascript:example(URLOne);'>LINK[/url]
<?php
}
?>

<?php
  switch ($level) {
    case 1:echo '<a href="javascript:example($URLone)">LINK</a>';break;
    case 2:echo '<a href="javascript:example($URLtwo)">LINK</a>';break;
    default:echo '<a href="javascript:example($URLthree)">LINK</a>';break;
  }
?>

 

Something like that?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.