The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

how do I write a function that queries a database with onchange?

I have no knowledge of javascript, and would like to write a function that queries my database using onchange. I have a dropdown which shows my mysql tables. when selected (and pushing the select button) it queries the database, and shows the contents of the table. How do I get rid of that submit button, and start using onchange. I tried searching around, but apparently this is a difficult topic to find. Anyone have any ideas?

let me try to be more descriptive....I currently have a dropdown, which queries, and shows a list of my tables. Upon selection (submit button) appears everything in the table under the dropdown. everything's all in one page with some if statements. How can I use the onchange to get it to do the same thing, without needing the submit button? Check out the link to view the page I'm talking about. I didnt really understand your reply, so I can't tell if its what I'm asking for or not.

I'm no expert, but Vinny's answer looks to be exactly what you're asking for: using the onchange event on the <select> to call a function which constructs the action attribute and fires the form submit.

This makes perfect sense now, onchange points to the action in the form, I got it. and if I want, I can put it like so mypage.php?mode=change in the action, and then use a php if statement to run the query, like so.

PHP Code:

if('change' == $_GET['mode']) {

}

That's awesome!!! Thanks a lot everyone. One problem I have though, my dropdown disappears when selected. here's the page I'm working on. http://dky.sytes.net/golesnew/cat/pickitem.php and here's the code, in case anyone knows a little php, and wants to see if they can tell my where my dropdown went??

Well, the dropdown doesn’t exactly “disappear.” Selecting something in the dropdown submits the form, which in turn takes you to the form-submission page. Since the dropdown isn’t on the form-submission page, it would give the effect of it “disappearing.”