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

后端 未结 1 784
死守一世寂寞
死守一世寂寞 2021-01-25 08:55

i\'m trying to write code when user which selects specific option from Dropdown menu then after selecting specific option. value gets printed next to dropdown menu. That value i

相关标签:
1条回答
  • 2021-01-25 09:11

    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.

    0 讨论(0)
提交回复
热议问题