I know php, but I'm new to Javascript and AJAX.
I have an ajax form that firsts requests that the user make a selection from the drop down. When the selection is made, a table is displayed. That all works great.
I have some input boxes to make additions to the table. That works great too EXCEPT... when I write the changes to the database, I need to use the id field from the drop down box in the where clause of my update query.
So my question is, how do I set a variable for later use when I make a selection from the drop down?
Setting A Variable With Javascript
Moderator: General Moderators
Re: Setting A Variable With Javascript
The variables you set in javascript run inside of a "virtual machine" in the browser. The PHP code runs inside of an apache module on the server. Hence var a=1; sets a variable in javascript. $a = 1; sets it in php, but the javascript variable in no way is related to the PHP variable.
What you'd do is write your value to a form element. Set a hidden field and then submit an HTML form. When PHP receives the request it can copy the request paramaters into some variables (after escaping them).
Since you're wanting to do ajax though you would be sending an XML document of variables via an RPC request. All complicated terms for simple stuff.
I like to use JSON. Not technically ajax because its asynchronous json not asynchronous xml. Here's a good tool if you just want to start playing around. http://api.jquery.com/jQuery.getJSON/ You'd have to download & include the Jquery script in your HTML document before using these commands.
Some of those examples will not make any sense until you learn about javascript closures, callbacks & objects.
What you'd do is write your value to a form element. Set a hidden field and then submit an HTML form. When PHP receives the request it can copy the request paramaters into some variables (after escaping them).
Since you're wanting to do ajax though you would be sending an XML document of variables via an RPC request. All complicated terms for simple stuff.
I like to use JSON. Not technically ajax because its asynchronous json not asynchronous xml. Here's a good tool if you just want to start playing around. http://api.jquery.com/jQuery.getJSON/ You'd have to download & include the Jquery script in your HTML document before using these commands.
Some of those examples will not make any sense until you learn about javascript closures, callbacks & objects.
Re: Setting A Variable With Javascript
I'll look in to it Josh, thanks!