jQuery select vaue to php function

I want to know if I can pass a select dropdown value to a php function
In other words when a user selects from dropdown list have the selected value then sent to a php function along with other values
leozayasAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gr8gonzoConsultantCommented:
Are you talking about passing it to PHP as part of a form submission or as part of an AJAX call or something else entirely?

As long as a <select> has a name attribute, it will be part of a form submission. If you need to access a dropdown value with Javascript, make sure the select dropdown has an id attribute and just use jQuery's val() call:

The HTML:
<select id='some_dropdown'> ... </select>

The jQuery Javascript:
alert($("#some_dropdown").val());
0
leozayasAuthor Commented:
No at the time of the function it will neither be a form submission nor ajax call.

I have a select type that the user selects a client from, which gives a numerical value of the client, later on in the page they also select from the keywords that they want to filter by.

This select calls a php function to build it, that chooses the keywords according to the client that was selected earlier. the php code is in a class file and take the form of getKeywords($client), it is here that I want to inject the client number that was chosen earlier.

Sorry for not being clear before

Thx
0
gr8gonzoConsultantCommented:
What you're describing -is- an AJAX call:
This select calls a php function to build it...

Open in new window


PHP runs on the server, Javascript runs on the client-side. They cannot talk to each other directly.

Imagine you own a restaurant. PHP is the chef in the back, and Javascript is the waiter in the front, who deals with the customers. Javascript can collect the order, but the waiter does not cook the meal right at the customer's table. Instead, the waiter writes down the order, he takes it back to the chef, and then the chef creates the meal, and gives back the finished results to the waiter. Then the water takes the prepared food to the customer.

This is how Javascript works with PHP. They don't talk directly. The waiter has no idea what the chef is doing and the chef has no idea what the waiter is doing. The waiter simply gives the order to the chef and the chef knows how to read it, but they operate in different rooms and on different schedules.

AJAX is simply the programming method that describes that back-and-forth communication, where Javascript temporarily goes to the kitchen to drop off the order with PHP, and PHP hands back the results.

That said, it sounds like you are  already doing an AJAX call to the script containing the getKeywords() PHP function. If you want to add another parameter, you need to update the PHP function to take a second parameter, like:

function getKeywords($client, $another_parameter)
{
   ...update the contents to use $another_parameter...
}

Then you need to find out how you are sending the AJAX call and update it to include the value of the <select> box using $("#your_dropdown").val().
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
leozayasAuthor Commented:
thank you, going by what you said, what i did was send an ajax call to a separate php file with the value of the select and built the new select there and sent it back.... :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.