Ana Houa Ana Houa - 1 month ago 14
Ajax Question

Languages for Bootstrap 3 selection change not working

I am using Languages for Bootstrap 3, but I am not able to figure out how get the selected language usig jquey or even the span do not allow href ( I was using alert() to see the result).

languga selector is as follow:



<div class="btn-group dropdown pull-right">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" >
<span class="lang-sm lang-lbl-full" lang="en"></span> <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" >
<li><span class="lang-sm lang-lbl-full" lang="ar" value="ar"></span></li>
<li><span class="lang-sm lang-lbl-full" lang="en" value="en"></span></li>
<li><span class="lang-sm lang-lbl-full" lang="fr" value="fr"></span></li>
</ul>
</div>




Answer

You can create javascript to figure out what span has been clicked like so:

function ChangeLanguage(selected) {
    alert(selected.value()); // Do whatever you want in here.
}

and activate it like so:

<div class="btn-group dropdown pull-right">
  <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" >
    <span class="lang-sm lang-lbl-full" lang="en"></span> <span class="caret"></span>
  </button>
  <ul class="dropdown-menu" role="menu" >
    <li><span class="lang-sm lang-lbl-full" onclick="ChangeLanguage(this)" lang="ar" value="ar"></span></li>
    <li><span class="lang-sm lang-lbl-full" onclick="ChangeLanguage(this)" lang="en" value="en"></span></li>
    <li><span class="lang-sm lang-lbl-full" onclick="ChangeLanguage(this)" lang="fr" value="fr"></span></li>
  </ul>
</div>