Can you a php script on the same page with ajax?

I been trying to find an answer on how to update a field in a form while using ajax for the last 3 days without any success. So instead I will try to break my question down to this:

English is not my first language and whenever I try finding help I always get the same results(result that I am not interested in lol)

can someone help me verbalize how I can type in Google search box → How to update a select/option field in a form while using ajax. I must have tried 500 variations and ran out of ideas. All that gets returned is how to dynamically update one select box according to the result of another select box. That’s not what I am looking for. I only want to update the current single, only select box on the form without having to reload the whole page. That’s it! nothing more. I don’t mind having the user clicking a button if it can’t be done automatically, I just want to refresh the darn select field.

Ajax is a way to pass information from the web page into a server side script and to then receive back information from that server side script to process in the page.

So to do what you want breaks up into several parts.

  1. An event occurs that triggers the need to update the select list.You would use an event listener to detect this.
  2. You get information from somewhere that identifies what is to be updated in the select list.
  3. An ajax request sends that information to the server
  4. Server side processing takes that information and processes it to work out what to return to the page.
  5. The ajax listener receives the information from the server.
  6. The subsequent JavaScript takes that information and adds the extra option to the select - new Option()

thanks felgall, let me see if I can fill in the blanks and keep it simple

1- click a button “refresh”
2- the whole content of the select list needs to be updated- in php I would simply query for the content and echo it in the option tag
3- that part I don’t know how to do
4- does that php script needs to be seperated from the form? Because right now all my php script and html are all in one file.
5- that part I don’t know how to do either
6- that is the elusive last step I have been looking for for the last 3 days

Please Note
This discussion was started to find what search terms to use.
The steps involved are being discussed here

I was attempting to point out that there are a number of steps involved and that any search would need to be done on how to perform a specific step. As they have already searched for all the alternatives for the entire task that they can think of I believe it is reasonable to assume that no page exists that describes how to carry out all of the steps. The search terms to use will therefore depend on which step of the process is being searched for.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.