Assign value using jQuery

assign values in jQuery
In applications we need to assign value in javascript or jQuery to the controls like label or hiddenfield. We will see sample code that assigns value to lable and hidden field using jQuery.

<html xmlns="">
<head runat="server">
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<title>assign value in jQuery</title>
<script type="text/javascript">
$(document).ready(function () {


function AssignValue() {
$("#message").html('New Value assigned');
$("#hiddenValue").val('New Value assigned');
return false;
<form id="form1" runat="server">
<label id="message">
Some Value</label>
<input type="submit" name="btnsubmit" id="btnsubmit" value="LogIn" onclick="return AssignValue();" />
<input type="hidden" id="hiddenValue" />

In above example if we want to assign value to hidden field and get hidden field value in code behind we need to remove "return false;" statement from jQuery code so that page will get postback.


Post a Comment