Passing javascript variable to PHP function
javascript, php
Solution
You can use jQuery for that to post an AJAX request. See this example taken out of jQuery documentation:
$.ajax({
type: "POST",
url: "some.php",
data: {groupFirstLetter:groupFirstLetter},
complete: function(data){
//data contains the response from the php file.
//u can pass it here to the javascript function
}
});
The variable will be available in your PHP code as `$_POST['groupFirstLetter']`. You can manipulate it as you wish then `echo` a response to the browser again and it will be available in the `data` variable. references:
jQuery AJAX
Problem
I have this javascript code ``` <Script> function getGroupId(){ var group=document.getElementById("selectedOptions").value; var groupFirstLetter=group.substring(2); } </Script> ``` I need to pass the `groupFirstLetter` to a PHP function which will count how many users in this group and return the value to the javascript function. Any ideas please? Thanks,