简体   繁体   中英

Pass a select option box value to PHP

So what I am looking to do is have a drop down box with options and when a option is chosen, there will be datas pulled from the Database and and place on the page.

How is it possible?

I tried passing it through jquery using the .post method, but I need to refresh the page, but I can't do that because the page is a form and by refreshing, we lose what the user have entered so far...

Thank you, Ara

Use JQuery post :

    $.post('<url>', {'input' : data},
        function(answer){
              alert(answer);
   });

You can set it not refresh the page.

按照Philippe的建议使用jquery .post,该页面将不会刷新。

You could also set the form up to come pre-filled with all of the values that the user entered (after the page refresh). I wouldn't suggest this as a replacement for the AJAX solution, but I still recommend it in addition, ie for graceful degradation.

I'm not sure if I understand what you need. But I guess you want to select some data from db and place it on your page. And this "select procedure" has to be triggered by changing value of some dropdown list before the form is submited right? So I would say you have to use something like this:

 $("#dropdownlist").change(function(){
        var jqxhr = $.get("getdata.php",{key : $(this).val() });
        jqxhr.success(function(response){
            // and place response on yr page
        });
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM