Solved

call javascript function with php and sending parameters

Posted on 2010-09-06
4
669 Views
Last Modified: 2012-06-27
i've an image galerry displaid in php calling a javascript fonction onmousehover
but it isn't called properly

html renders this (for exemple) <img border="0" alt="/img/imagette_10.gif" onmouseover="javascript:newfunction(this,1,en)" src="/img/imagette_10.gif" class="imagette2">
if i put the mouse hover nothing happens but
if with firebug i add 'apostrohers around the two parameters  that means i ve now in my html javascript:newfunction(this,'1','en') it works,
what should i put in my php file to correct my script? sample php code
thanks
<?php echo '<a href="#" title="'.$infos.'"><img class="'.$sClassName.'" src='.$resultat['chemin'].' onmouseover="javascript:newfunction(this,'.$resultat["id"].','.$lang.')" border="0" alt="'.$resultat['chemin'].'"  /></a>';
?>

Open in new window

0
Comment
Question by:jerrrrry
4 Comments
 
LVL 15

Accepted Solution

by:
gplana earned 250 total points
Comment Utility
just put this line:
<?php $lang = "'" . $lang . "'"; ?>
before your actual code:
<?php echo '<a href="#" title="'.$infos.'"><img class="'.$sClassName.'" src='.$resultat['chemin'].' onmouseover="javascript:newfunction(this,'.$resultat["id"].','.$lang.')" border="0" alt="'.$resultat['chemin'].'"  /></a>';
?>

This will add apostrophers surrounded the content of $lang into the $lang variable.

Hope it helps.
0
 
LVL 42

Expert Comment

by:Chris Stanyon
Comment Utility
Maybe the PHP shortcut for echoing will help. I often find it easier to echo 'inline', rather than concatenating a string.

If you use the shortcuts, you can echo PHP values anywhere in your HTML with the minimum of fuss.

<p>The value of myVariable is <?=$myVariable?></p>


<a href="#" title="<?=$infos?>"><img class="<?=$sClassName?>" src="<?=$resultat['chemin']?>" onmouseover="javascript:newfunction(this,'<?=$resultat['id']?>','<?=$lang ?>')" border="0" alt="<?=$resultat['chemin']?>" /></a>

Open in new window

0
 
LVL 15

Expert Comment

by:Insoftservice
Comment Utility
Hi,

<?php echo '<a href="#" title="'.$infos.'" onmouseover="javascript:newfunction(this,'.$resultat["id"].','.$lang.')" >
<img class="'.$sClassName.'" src='.$resultat['chemin'].' border="0" alt="'.$resultat['chemin'].'"  /></a>';
?>
0
 

Author Closing Comment

by:jerrrrry
Comment Utility
tks
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

743 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

15 Experts available now in Live!

Get 1:1 Help Now