0

I have a JQuery function in which I am trying get the value of select field from my HTML.

$('.selectCurrency').change(function(){
        //alert(this.value);
        alert("{{$users["+this.value+"]->currency}}");
});

Its throwing error in this.value.

Any suggestions how I can get the value?

bob
  • 4,282
  • 2
  • 22
  • 30
user3201500
  • 1,538
  • 3
  • 22
  • 43
  • This is not possible. PHP runs on the server, JS on the client. The two cannot directly interact as you are attempting. To pass a JS value to PHP you would be best to make an AJAX request. – Rory McCrossan Feb 23 '16 at 11:18

1 Answers1

-1

Just use the .val() function in jQuery. http://api.jquery.com/val/

Gavin Thomas
  • 1,196
  • 6
  • 10
  • That's not a very useful reply. I'm pretty sure it **will** work once you do it correctly. – Gavin Thomas Feb 23 '16 at 11:26
  • I used it like this `alert("{{$users["+$(this).val()+"]->currency}}")` any other method you will suggest? – user3201500 Feb 23 '16 at 11:28
  • Yes - not using it like that. Please read the documentation that I linked - it provides you with all the information you need. `$('.selectCurrency:selected').val();` – Gavin Thomas Feb 23 '16 at 11:32