Solved

call javascript function with php and sending parameters

Posted on 2010-09-06
4
672 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
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
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…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

860 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