Solved

call javascript function with php and sending parameters

Posted on 2010-09-06
4
675 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
[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
4 Comments
 
LVL 15

Accepted Solution

by:
gplana earned 250 total points
ID: 33613776
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 43

Expert Comment

by:Chris Stanyon
ID: 33614087
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
ID: 33616172
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
ID: 33616238
tks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

623 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