In how many ways can i get value from a html selec

2020-01-19 04:20发布

问题:

i am learning php along with mysql and so developing a e-comm site it is very exiting when i get hindered by some error but this time it just a html thing that has stopped my constuction.

so, i have to populate 2 <select> tags in a addProduct form for Category and sub-category but i need to work on onChnage event for category select list, as to populate the sub-category select list on basis of the user selection in category select list. i have searched a lot and some how i can do it but i want to know what are the possible ways and what is the safest way? also can i build a php function to do this if yes how to get the element value without submitting the form since it will submit all the form data that will empty all other fields. thank you!

回答1:

onChange events are handled by javascript, PHP is finished processing before the user sees the loaded webpage.

To do what you are asking, you will want to utilize javascript/AJAX to update the page "on the fly"



标签: php html forms