Click here to Skip to main content
15,900,461 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
for suppose i want to select dropdownlist that value will be send to the server without clicking button in html5.please help me.
Posted
Comments
phil.o 8-Oct-13 8:42am    
Nice requirement!
Please see here and here before.
Murali Gowda 9-Oct-13 1:49am    
Though I have given you a solution, please do refer to phil.o's comment before asking for help

1 solution

You can write onchange event for dropdown list and in javascript make an ajax call with the data i.e selected value to the method or service i.e the server.

Consider the following example,

HTML:

HTML
<select id="ddl" onchange="sendToServer()">
    <option value="1">One</option>
    <option value="2">Two</option>
    <option value="3">Three</option>
    <option value="4">Four</option>
</select>


JavaScript:

JavaScript
function sendToServer(){
    var element = document.getElementById("ddl");
    var selectedValue = element.options[element.selectedIndex].value;
    
    //Make ajax call to send selected value to server
    $.ajax({
        url : "put service/method url",
        type : "post",
        data : {value : selectedValue},
        success : function(result){
                     //code block -- executes when the data is posted successfully
                  },
        error : function(xhr, status, error){
                // executes when any error or exception occurred in server
                }
    });
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900