In a MySQL database, I have a table of items with the item's ID, name and default price. I wish to have a form with a drop-down menu of all the items in the table that changes the price in an input field to the default price of the item selected. How exactly would I go about doing this with Javascript? Thanks in advance.
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
Using jQuery, you can do something like this:
Create Select dropdown menu like below where option value = price of item
JS:
Whats your server side language?
I would just do something like this:
where the drop down is item_drop_down and the input you want the price in is item_price_input.
HTML:
JavaScript (using jQuery):
And see this jsFiddle for a working example: http://jsfiddle.net/chnUn/
Get all the things you need to display from your server (preferably in JSON)
and generate your
select
elements like this..You can get default price like