I have a page that allows individuals to use a select drop down box to choose from a number of items for an invoice. What i would like to happen, is when an item from the list is chosen, the current number in stock generates in a disabled text box to the right. This obviously needs to happen before form submission, but i am a newbie at javascript and need it to have it work alongside php.
The javascript will be quite separate to your PHP.
Try posting the code of a simple HTML page with the minimum elements to illustrate what you are trying to do.
You can use a php file to retrieve the number of items for a certain item, by calling the php file with a querystring that contains the item you want to get the number of.
So for example, if it were popcorn, a call to
/path/to/numberofitems.php?item=popcorn
would result in the a value of 15 being echo’d out.
If you use item ids, it could instead be:
/path/to/numberofitems.php?itemid=10293
Here’s how you could use that with a function that triggers when the select field is changed.
Paul has a good solution above that would do what you are wanting.
I might do without the ajax request though and put the values as well as quantities in the page to begin with.