passing values between php and javascript

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tinks
Forum Newbie
Posts: 5
Joined: Mon Oct 18, 2010 2:32 am

passing values between php and javascript

Post by tinks »

hello there,

can somebody help me with my php/javascript code?

i want to load the corresponding data to a form everytime the user
selects an entry from a listbox.

the listbox contains the ID which i use to lookup in my database.
i already have the javascript function that calls an external php file to
query the database.

I can already retrieve the specific records from my db depending on the selected option.

my problem is on how to populate the form with the data that i got.
from my external php, i dont know how to access the fields of the html page or how to send back the values to the calling javascript function.

how would i go about this one?

help please. thank you.
internet-solution
Forum Contributor
Posts: 220
Joined: Thu May 27, 2010 6:27 am
Location: UK

Re: passing values between php and javascript

Post by internet-solution »

tinks wrote:I can already retrieve the specific records from my db depending on the selected option.
You have two options, depending on your form:

After you retrieve the records, are you passing the records to Javaacript? If so, you can populate the HTML fields by JavaScript.

Other option is to put the fields that needs updating in a separate div. Generate HTML code for the whole div in PHP and then pass this to JavaScript. Then use innerHTML.value = .. to update the form.
Post Reply