how print record from database when user select options from Dropdown menu? dynamic program

爱⌒轻易说出口 提交于 2019-12-02 05:17:47

When you print your select box,you can passed parameter onChange="sendInfo(this.value);" function like below :

$('<div>
<!--adding onchange and passing selected value to it-->
 <select class="selected-meal-type" onchange ="sendInfo(this.value);">
<option value="TYPE A">TYPE A</option>
<option value="TYPE B">TYPE B</option>
<option value="TYPE C">TYPE C</option>
 </select>&nbsp;&nbsp;<span id="amit" /></span>
 </div>
 <br>').appendTo('#container');

Now in your sendInfo function do like below :

        function sendInfo(str)//str will have value selected from dropdown list   
                {  
                   //attaching this value in url
                    var url="process.jsp?val="+str;  
                   if(window.XMLHttpRequest)
                    {  

                        request=new XMLHttpRequest();  
                    }  
                    else if(window.ActiveXObject)
                    {  
                        request=new ActiveXObject("Microsoft.XMLHTTP");  
                    }  


                        request.onreadystatechange= function() {
            if (this.readyState == 4 && this.status == 200) {
                document.getElementById("amit").innerHTML = this.responseText;
               }
            }; 
                        request.open("GET",url,true);  
                        request.send();  
                   } 

Also don't forget to add div with id amit.Now ,if you select Type B then, val will have value TypeB ,use this in your select query and sent result back to your jsp page.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!