Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
86
rated 0 times [  89] [ 3]  / answers: 1 / hits: 16399  / 11 Years ago, wed, september 4, 2013, 12:00:00

this is my 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 i send the javascript var ll value to mypage.php



Actually I want the image alt value to pass it, How it is possible please give some idea..


More From » php

 Answers
3

create a hidden field inside the <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 then you have ll in PHP, when you submit the form.






update



I guess you wonder if you have links instead of a form, like 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 you just want to reload the page with ll containing the 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 your page, eg ex mypage.php?ll=it_IT. As with the form accessible in mypage.php through $_GET['ll']



Using jQuery here, since you have it on your tag-list (and it was the far easiest / fastest to produce :)


[#75899] Tuesday, September 3, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jimmieo

Total Points: 515
Total Questions: 102
Total Answers: 110

Location: Kazakhstan
Member since Mon, Sep 26, 2022
2 Years ago
;