Tuesday, August 6, 2013

Bind data to Asp.net text box using dropdownlist in jquery

Title: JQuery set text box value in asp.net

In recent articles we known how to implement the  Data binding concept on data  controls like grid view,Data list,list etc.Here i would like to explain how to bind data to asp.net text box while leave the focus on Drop Down List using JQuery blur function.The blur function will fire when the previous controls has lost focus.

<html xmlns="http://www.w3.org/1999/xhtml">
<title>Bind data to Asp.net text box using DropDownList in jquery</title>
<script type="text/javascript" src="~/jquery.min.js" ></script>
$(document).ready(function() {
var SalesOrderText = $("#ddlSalesOrder option:selected").text();
$("#<%= txtOrderTotalAmt.ClientID %>".val(SalesOrderText); 
Amount: <asp:DropDownList ID="ddlSalesOrder" runat="server">
TotalAmount:<asp:TextBox ID="txtOrderTotalAmt" runat="server"></asp:TextBox>
As you can see there is alert to confirmation for drop down selected value will come when the blur event occurs.Whenever we are using JQuery ,we should add JQuery library reference to our application.
In the above example we have taken one drop down list and text box to display the amount order .When the amount Drop down list has lost the focus ,the total Amount will be populate automatically.

No comments: