PHP Combobox Javascript populate txtbox

Hi,
I am struggling to work out the best way to do this i have a combobox populated from a SQL DB coded in PHP. What i was wanting was a once the selection of the combobox has been chosen say for example BBC it populates 2x textboxes automatically with the phone number and notes from the SQL DB relating to that choice.

Example:
Comobox: Selection “BBC”
Textbox1 AutoPopulated from Combox Selection: “01274 569852”
Textbox2 AutoPopulated from Combox Selection: “Use this to watch news”

I amy be in the wrong forum topic if so please move this to the relative forum topic

Okay, so what have you planned out on how to do this?

Is it handled thru and AJAX call, or page load?

At the moment it is on page load and it just populates the combobox. I have been trying to workout if this is the best way to do this.

From research if i use PHP i would have to re-load the page as the page load has already populated the combobox values so i would have to reload the page to get the textbox entires.

If i use AJAX it should work correctly but struggling on how to get it to populate the SQL DB combobox values and then pull the correct values on the combobox entire.

I have no code to go on at the moment trying to veiw tutorials on how best to acheive this it will be a first for me.

If this was my project I would first look up an example of how to use Ajax in Javascript or using jquery. Then I would build out an endpoint/new web page just for this that accepts parameters. Then use Ajax to pass the parameters that were selected by the user to the new endpoint, have your endpoint get the parameters, perform a new query for the new material based on input and return it to the page. Once done you can use more Javascript to determine which new combo boxes to make and dynamically add them.

One thing to watch out for is making sure that you sanitize the input from your Ajax call on the back end before using it in your query and it’s best to use bound parameters in your query.

I have written some code this afternoon and everytime my select box selects a value from the SQL populated list i get Empty string passed to getelementbyid() it prob my coding i have put this together looking at tutorials & past code.

It all looks ok from what i can tell but cannot see where to post the code i have cooked up.

Thanks James

What’s the code you have? It’s easier to figure out what’s going on when you can see it, rather than guess what might be happening.

I would but since the update its wrecking the format of the code or not displaying it all it was simple in the old format???

I fixed the post formatting.

Thank you astonecipher :smiley: is do you have to indent every line?

No, you just have to use three back ticks.

```

Sponsor our Newsletter | Privacy Policy | Terms of Service