dynamic value of dropdown in ajax

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • techbytes
    New Member
    • May 2010
    • 36

    dynamic value of dropdown in ajax

    hai,


    I have a dropdown which has dynamic values.When I select a particular value in the dropdown,i want to diaplay
    corresponding details .

    I donot know how to get the dynamic value from the dropdown using ajax and how to display the details.

    give suggestions to do it.
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    Hi, You can do it easily.
    Code:
    <html>
    <head>
    <script type="text/javascript">
      function doThis()
       {
        
    	var x = document.getElementById('myText').value;
    	 if(x==""||x==null||x==false)
             {
                  alert("Please Enter the Value in the Text Field");
                  document.getElementById('myText').focus; 	
             } 
             else
             {
    			if(window.ActiveXObject)
    				document.getElementById('mySelect').add(new Option(x,x));	
    			else
    				document.getElementById('mySelect').add(new Option(x,x),null);	
    		}  
       }
    </script>
    </head>
    <body>
    Enter Text: <input type="text" id="myText" name="myText">
    &nbsp;&nbsp;&nbsp;
    <input type="button" value="Add to Combo" onclick="doThis()">
    <br/><br/>
    <select id="mySelect" name="mySelect" onchange="alert(this.options[this.selectedIndex].value);">
     <option>Select</select>
    </select>
    </body>
    </html>
    This is a sample code for dynamically adding values in select box. In the select I have used onchange listener. In that you can fetch the value like that. With that value make your own Ajax call.

    Thanks and Regards
    Ramanan Kalirajan

    Comment

    Working...