Mavengers
Developer's Blog
Wednesday, April 15, 2015
asp.net listbox select items by value jquery
$.each(data[0].Work.split(","), function (i, e) {
$("#<%=lb.ClientID%> option[value='" + e + "']").prop("selected", true);
});
jQuery event.preventDefault() Method
The event.preventDefault() method stops the default action of an element from happening.
For example:
Prevent a submit button from submitting a form
Prevent a link from following the URL
$("a").click(function(event){
event.preventDefault();
});
Prevent a link from opening the URL:
Javascript Ajax Syntax
function Create() {
var parameters = {
DepartmentId: hddepartmentId
};
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: baseUrl + 'Case/Create',
data: JSON.stringify(parameters),
dataType: "json",
success: function (data) {
alert("Success");
},
error: function (result) {
//alert("Error in case creation");
//alert(result);
}
});
}
Javascript Redirect to page
function Redirct() {
window.location.href = "webpages/dashboard.aspx";
}
Jquery CHECKS IF THE KEY PRESSED IS A NUMERIC OR DECIMAL VALUE
function isNumber(evt, element) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (
(charCode != 45 || $(element).val().indexOf('-') != -1) && // “-” CHECK MINUS, AND ONLY ONE.
(charCode != 46 || $(element).val().indexOf('.') != -1) && // “.” CHECK DOT, AND ONLY ONE.
(charCode < 48 || charCode > 57))
return false;
return true;
}
$('input[id$=txefetAmount],input[id$=txtsdfAmount],input[id$=txtsdAmount]').keypress(function (event) {
return isNumber(event, this)
});
asp.net Jquery Validation Integer Only
$(function () {
$('input[id$=txt]').keydown(function (e) {
if (e.shiftKey || e.ctrlKey || e.altKey) {
e.preventDefault();
} else {
var key = e.keyCode;
if (!((key == 8) || (key == 46) || (key >= 35 && key <= 40) || (key >= 48 && key <= 57) || (key >= 96 && key <= 105))) {
e.preventDefault();
}
}
});
});
asp.net Javascript/jQuery: Set Values (Selection) in a multiple Select
1) <asp:ListBox ID="lbWork" runat="server" SelectionMode="Multiple" CssClass="fullwidth "></asp:ListBox>
2) $.each(data[0].Work.split(","), function (i, e) {
$("#<%=lbWork.ClientID%> option[value='" + e + "']").prop("selected", true);
});
Newer Posts
Older Posts
Home
Subscribe to:
Posts (Atom)