How to pass the javascript variable value to php variable? -


this javascript code

<script type="text/javascript">     function myfunc(lang){     var ll = lang;                   //alert(ll);     } </script> 

my html code

<form  method="post" action="mypage.php?>">    <div>         <input type='image' src='/images/flags/us.png' name='us' value='en_en' onclick='myfunc(this.value)'/>    <input type='image' src='/images/flags/it.png' name='it' value='it_it' onclick='myfunc(this.value)'/>  <input type='image' src='/images/flags/fr.png' name='fr' value='fr_fr' onclick='myfunc(this.value)'/>      </div> 

now how can send javascript var ll value mypage.php

actually want image alt value pass it, how possible please give idea..

create hidden field inside <form>

<input type="hidden" name="ll" id="ll"> 

in javascript

<script type="text/javascript">     function myfunc(lang){         var ll=document.getelementbyid('ll');         ll.value=lang;     } </script> 

and have ll in php, when submit form.


update

i guess wonder if have links instead of form, this? :

<a href="#" class='lang'><img src="images/flags/it.png" alt="it_it" /></a> <a href="#" class='lang'><img src="images/flags/fr.png" alt="fr" /></a> <a href="#" class='lang'><img src="images/flags/us.png" alt="en_en" /></a> 

and want reload page ll containing desired language code?

<script type="text/javascript"> $('.lang').click(function() {     var lang = $(this).find('img').attr('alt');     document.location.href='mypage.php?ll='+lang; }); </script> 

will reload page, eg ex mypage.php?ll=it_it. form accessible in mypage.php through $_get['ll']

using jquery here, since have on tag-list (and far easiest / fastest produce :)


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -