Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

Making an image trigger an action

images php coding issues or problems here.

Moderators: macek, egami, gesf

Making an image trigger an action

Postby bugmenot » Tue May 31, 2011 8:56 am

Hi everyone,
I´m, trying to internationalizate my web.
I want to know how to make an image trigger an action, so that the user can choose the idiom by clicking on the image.
I was trying like this.
<img src="../images/banderas/espaniol.ico" id="es" value="es" action="idioma2.php" method="post" />
<img src="../images/banderas/euskera.ico" id="eu" value="eu" action="idioma2.php" method="post" />
<img src="../images/banderas/ingles.ico" id="en" value="en" action="idioma2.php" method="post" />
and then something like this in idioma2.php
if($_SESSION["eu"]!="")
$lang=$_SESSION["eu"];
elseif ($_SESSION["es"]!="")
$lang=$_SESSION["es"];
elseif ($_SESSION["en"]!="")
$lang=$_SESSION["en"];
It´s probably crazy, but i´m newby in php.
Thanks!
bugmenot
New php-forum User
New php-forum User
 
Posts: 4
Joined: Thu Sep 01, 2005 9:04 am

Re: Making an image trigger an action

Postby egami » Tue May 31, 2011 10:08 am

in order to make an image be an action, it has to be either a link, or a form.

a simple javascript can make it a post form, or you just create it as a link..


ie..

<a href="thispage.php?lang=en"><img src="english.jpg"></a>


or..
a form..

<form name="english" method="post" action="thispage.php">
<input type="hidden" name="lang" value="en">
<a href="javascript:document.english.submit();"><img src="english.jpg"></a>
</form>


that should get you in the right direction.
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Making an image trigger an action

Postby bugmenot » Wed Jun 01, 2011 7:11 am

Thanks a lot!
bugmenot
New php-forum User
New php-forum User
 
Posts: 4
Joined: Thu Sep 01, 2005 9:04 am

Re: Making an image trigger an action

Postby gandahar » Thu Jun 09, 2011 5:49 am

easiest javascript solution

no need forms, no need to create a javascript function, no need a href link....

Code: Select all
<img src="img.jpg" onclick="document.location.href='mapage.php?lang=fr';">
User avatar
gandahar
New php-forum User
New php-forum User
 
Posts: 112
Joined: Tue Mar 15, 2011 4:05 am


Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.