Wednesday, February 4, 2015

JQUERY CLIENT SIDE VALIDATIONS

To get TextBox value without Master Page
var firstName = $('#txtFirstName').val()

To get TextBox value with MasterPage for TextBox
var subject = $(GetClientID('CallsSubjectTxt')).val();

To get drop down Text with Master Page
var callType = $(GetClientID('CallTypeDrp')).find('option:selected').text();

To get drop down Text without Master Page
var countryText = $('#DropDownList1').find('option:selected').text()

To get drop down Id without Master Page
var callTypeID = $('#CallTypeDrp')).val()

To get drop down Id with Master Page
var callTypeID = $(GetClientID('CallTypeDrp')).val()


To check checkbox validation with Master Page
if ($(GetClientID('RemainderChk')).is(':checked'))
            RemainderCheck = 1;
        else
            RemainderCheck = 0;

To check checkbox validation without Master Page
if ($('#RemainderChk')).is(':checked'))
            RemainderCheck = 1;
        else
            RemainderCheck = 0;


To find out all checked check boxes

$("input[type='checkbox']:checked").each(
    function() {
       // Your code goes here...
    }
);



var isChecked = $('#chkSelectBox').attr('checked')?true:false;
Here if check box is checked it returns true, else undefined




var isChecked = $('#chkSelectBox').prop('checked');

prop() will return true or false 





Label Validations:



<head runat="server">
    <title></title>
    <script src="jquery-1.7.min.js"></script>
    <script type="text/javascript">
            $(document).ready(function () {
                var lablevalue = $('#Label1').text();
                alert('Label Value ' + lablevalue);
            });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div class="divClassusingID" style="width:400px"> 
        <asp:Label ID="Label1" runat="server" Text="hi uday"></asp:Label>

    </div>
    </form>
</body>



output:




To get label value with master page

$('#<%=Label1.ClientID%>').text();


To get label value without master page
$('#Label1').text();

-----------------------------------------------------------------------------------------

Set label value with master page
$('#<%=Label1.ClientID%>').text("New Value");


Set label value without master page

$('#Label1').text("dotnetbyudayrajakonda.blogspot.in");


Example:


<head runat="server">
    <title></title>
    <script src="jquery-1.7.min.js"></script>
    <script type="text/javascript">
            $(document).ready(function () {
                var lablevalue= $('#Label1').text("dotnetbyudayrajakonda.blogspot.in");
            });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div class="divClassusingID" style="width:400px"> 
        <asp:Label ID="Label1" runat="server" Text="hi uday"></asp:Label>
    </div>
    </form>
</body>





Output:





Set Textbox value with Master Page
$('#<%=TextBox1.ClientID%>').val("New Value");

Set Textbox value without Master Page
$('#TextBox1').val("HI uday");


<head runat="server">
    <title></title>
    <script src="jquery-1.7.min.js"></script>
    <script type="text/javascript">
            $(document).ready(function () {
                var a=$('#TextBox1').val("HI uday");
            });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div class="divClassusingID" style="width:400px"> 
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </div>
    </form>
</body>



Output:

Set Dropdown value with Master Page
$('#<%=DropDownList1.ClientID%>').val("hi");

Set Dropdown value without Master Page
$('#DropDownList1').val("hi");

Get text of selected item in dropdown with Master Page
$('#<%=DropDownList1.ClientID%> option:selected').text();

Get text of selected item in dropdown without Master Page
$('#DropDownList1 option:selected').text()

Make textbox as Read only
$('#TextBox1').attr('readonly', 'readonly');


<head runat="server">
    <title></title>
    <script src="jquery-1.7.min.js"></script>
    <script type="text/javascript">
            $(document).ready(function () {
                $('#TextBox1').attr('readonly', 'readonly');
            });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div class="divClassusingID" style="width:400px"> 
        <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
    </div>
    </form>
</body>


To disable texbox



Using check box
$('#CheckBox1').attr('checked');





output:



Example:







No comments:

Post a Comment

Thank you for visiting my blog

Kubernetes

Prerequisites We assume anyone who wants to understand Kubernetes should have an understating of how the Docker works, how the Docker images...