Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
-1
rated 0 times [  1] [ 2]  / answers: 1 / hits: 17247  / 12 Years ago, tue, april 10, 2012, 12:00:00

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,


More From » php

 Answers
51

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


[#86343] Sunday, April 8, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ashelye

Total Points: 479
Total Questions: 97
Total Answers: 85

Location: Benin
Member since Fri, Mar 24, 2023
1 Year ago
;