-1

So i've a dropdown menu of my Languages, the HTML/JS output is like this:

<div class="dropdown-menu  dropdown-menu-right show">
<a class="dropdown-item " ng-click="changeLang('1')">English</a>
<a class="dropdown-item " ng-click="changeLang('2')">Spanish</a>
<a class="dropdown-item active" ng-click="changeLang('3')">French</a>

the selected one in the code above is French, (class="dropdown-item active")

my PHP code in the controller is this:

<a class="nav-link dropdown-toggle text-muted waves-effect waves-dark" href="" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <i class="flag-icon flag-icon-fr"></i></a>

As you can see above, whenever i change the value of the dropdown menu, the icon still pointing to French (obviously because hardcoded)

how do i catch the active one and refer to it in my PHP code ?

Br3x
  • 754
  • 4
  • 10
  • 21
  • Before continuing, please read [this](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – Teemu Jul 29 '18 at 21:11
  • what you mean "how do i catch the active one and refer to it in my PHP code ?" ? What do you want to achive? What is body of your `changeLang` function? – colorgreen Jul 29 '18 at 22:25

1 Answers1

1

You should definitely look into using JavaScript for this - my thought process would be to set a cookie defining the currently selected option and then appending some HTML to the element. This would eliminate the need to catch this server side and re-render the page. Plus it has the added benefit of sending the option to the server on every request in case you need to perform some other action with it.

gmemstr
  • 135
  • 1
  • 2
  • 8