Note that there are some explanatory texts on larger screens.

plurals
  1. POChange jquery function triggered by drop down
    text
    copied!<p>I have been trying to resolve this for hours, but with no success. I also searched the existing questions, but did not find the correct answer :-/ </p> <p>I currently have a drop down on my website which triggers a function to change the active language on the sessions table. What I was trying to do is to get rid of the ugly drop down and replace it with a fancybox to change the language. All works fine except of triggering the change function and I would need your help on changing the jquery code in order to to the same function as the drop down does, but now triggered by a text link. Here is the old drop down:</p> <p>Dropdown:</p> <pre><code>&lt;form id="language-selection-form" method="post" action="&lt;?php echo base_url();?&gt;/index.php/home/save_lang_change"&gt; &lt;?php $lang = $this-&gt;session-&gt;userdata('language'); ?&gt; &lt;select id="language-selection" name="language-selection"&gt; &lt;option value="spanish" &lt;?php echo (!empty($lang) &amp;&amp; $lang == 'spanish') ? 'selected="selected"' : ''; ?&gt;&gt;Espanol&lt;/option&gt; &lt;option value="german" &lt;?php echo (!empty($lang) &amp;&amp; $lang == 'german') ? 'selected="selected"' : ''; ?&gt;&gt;Deutsch&lt;/option&gt; &lt;option value="english" &lt;?php echo (!empty($lang) &amp;&amp; $lang == 'english') ? 'selected="selected"' : ''; ?&gt;&gt;English&lt;/option&gt; &lt;/select&gt; &lt;/form&gt; </code></pre> <p>jQuery:</p> <pre><code>&lt;script type="text/javascript"&gt; var http_host_url = "&lt;?php echo base_url(); ?&gt;"; jQuery(document).ready(function(){ jQuery('#language-selection').change(function(){ /*var lang = $(this).val(); $.ajax({ type:'post', url: http_host_url + "index.php/home/save_lang_change", data: { lang: lang }, success: function(html){ console.log(html); } }) */ jQuery('#language-selection-form').submit(); }) })&lt;/script&gt; </code></pre> <p>now, the new script would be:</p> <pre><code>&lt;a class="fancybox" href="#lang_change"&gt;&lt;img src="&lt;?php echo base_url() ?&gt;app/css/images/flags/es.png" /&gt; Español&lt;/a&gt; &lt;div id="lang_change" style="width:200px;display: none;"&gt; &lt;h3&gt;Choose your language:&lt;/h3&gt;&lt;br/&gt; &lt;p align="center"&gt;&lt;img src="&lt;?php echo base_url() ?&gt;app/css/images/flags/es.png" /&gt;&amp;nbsp;Español&lt;/p&gt; &lt;p align="center"&gt;&lt;img src="&lt;?php echo base_url() ?&gt;app/css/images/flags/gb.png" /&gt;&amp;nbsp;English&lt;/p&gt; &lt;p align="center"&gt;&lt;img src="&lt;?php echo base_url() ?&gt;app/css/images/flags/de.png" /&gt;&amp;nbsp;Deutsch&lt;/p&gt; &lt;/div&gt; </code></pre> <p>but of course, it does not trigger the jquery function. </p> <p>here is the function in the home.php controller:</p> <pre><code>function save_lang_change(){ //echo $_POST['language-selection'] . " hjkh ff"; $lang = $_POST['language-selection']; $this-&gt;load-&gt;library('session'); $this-&gt;session-&gt;set_userdata("language", $lang); //echo $this-&gt;session-&gt;userdata("language"); redirect(base_url()); } </code></pre> <p>Any idea on how to resolve this? Thanks in advance ;-)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload