Solution var checkEmpty = function () { var formInvalid = false; if ($("#UserRole").val() === '') { formInvalid = true; } if (formInvalid) { alert('The fields is empty. Please Enter the User Role'); return false; } else return true; }
Function to validate name for numbers and special characters
Solution In Jquery var ValidateName= function (usr) { var regexp = new RegExp('^[A-Za-z]+$'); var check = $(usr).val(); if (!regexp.test(check)) { alert('Numbers and Special Characters are not allowed'); $('#UserRole').css('border-color', 'red'); return false; } else { $('#UserRole').css('border-color', 'green'); return true; } } HTML <div class="col-sm-4 tb-font"> @Html.Label("Role", "User Role", new { style = "width:140px; margin-bottom:5px; margin-top:5px; float:... Continue Reading →
Function to Compare text of Password and Confirm Password field and placing it in document.ready function
Solution <script> $(document).ready(function () { $('#Password, #CPassword').on('change', function () { var ps = $("#Password").val(); var cps = $("#CPassword").val(); if (ps != null && ps != '' && cps != null && cps != '') { if (ps != cps) { alert("Please Enter the same Password in both fields"); $('#Password').css('border-color', 'red'); $('#CPassword').css('border-color', 'red'); } else {... Continue Reading →
Call a function when the view loads in an MVC application
Solution Document.ready function is for this purpose. For example, you want to call a function that fills a drop-down dynamically when the view loads, you will give that function a call in document.ready function enclosed in the script tag <script> $(document).ready(function () { fillRoles(); }); </script> In the above example, function fillRoles() is called to... Continue Reading →
Find a value of dropdown by text and set it as selected value in jquery
Solution var myText = "Pakistan"; $("#CountryDropDownList option:contains(" + myText + ")").attr('selected', 'selected');
Setting selected value of a dropdownlist using jquery
Solution var val="abc"; $("#dropdown > [value=" + val + "]").attr("selected", "true");
Hashing Passwords-Easier Password Management by creating and storing the salt and the hashed password in a single value.
Include header using System.Web.Helpers; In View: To take input <div class="col-sm-4 tb-font"> @Html.Label("UName", "User Name", new { style = "width:140px; margin-bottom:5px; margin-top:5px; float: left;" }) @Html.TextBox("UserName", null, new { @class = "form-control text-box" }) </div> <div class="col-sm-4 tb-font"> @Html.Label("Pswrd", "Password", new { style = "width:140px; margin-bottom:5px; margin-top:5px; float: left;" }) @Html.Password("Password", null, new { @class... Continue Reading →
Set selected value as empty for dropdownlist via jquery
Solution $("#elementId").val(''); e.g. $("#ddlMain").val('');
Disabling a text-box in ajax ASP.NET
Solution document.getElementById("myText").disabled = true;
Return bool value from ajax
Returning bool value from ajax is not similar to any simple function that returns the bool value. BUT DON'T WORRY! it isn't even too difficult. it's just slightly different. Solution var alreadyExists = function () { var role = $("#UserRole").val(); var notexists = false; $.ajax ({ url: "@(Url.Action("checkExists", "UserManagement"))", data: { role: role }, contentType:... Continue Reading →