See figure below to know how to get length of options using JQuery select :
This blog is dedicated to share my experience during my development as a purpose of notes and explorer various web / enterprise technologies like JAVA , JEE , Spring ,hybris, Portal , Jquery , RAI , JMS, Weblogic , SSL , Security, CS, MAC< Linux, Windows, Search, IOT, Arduino, Machine Learning, Tips, Angular, Node JS, React, Mac, Windows, Stack, Exception, Error etc. with examples.
Search This Blog
Showing posts with label JQuery. Show all posts
Showing posts with label JQuery. Show all posts
Wednesday, October 21, 2009
Friday, October 9, 2009
JQuery How to restict text box and text area to enter number
Try out following JQuery script , It will allow to enter 14,3 combination to text box. i.e
decimal number with max 14 (without .) and maximum of 3 decimal.234.
input type="text" id="transAmtField"/
$(document).ready(function() {
restrictInt(14,3);
});
var oldAmount;
function restrictInt(num,decimal) {
var amount;
var newNum=0;
$("#transAmtField").bind('keyup', function(e) {
amount = $("#transAmtField").val();
if(isNaN(amount)) {
$("#transAmtField").val(amount.replace(/[^0-9\.]/g,''));
return false;
}
if(amount.lastIndexOf(".") != -1) {
if(amount.length-amount.lastIndexOf(".") > decimal+1 ){
$("#transAmtField").val(oldAmount);
return false;
} else if(amount.length <= num+1) {
oldAmount = amount;
return true;
} else {
oldAmount = amount.substring(0,num+1);
$("#transAmtField").val(oldAmount);
return false;
}
}
if(amount.lastIndexOf(".") == -1) {
if(amount.length <= num) {
return true;
} else {
oldAmount = amount.substring(0,num);
$("#transAmtField").val(oldAmount);
return false;
}
}
});
}
decimal number with max 14 (without .) and maximum of 3 decimal.234.
input type="text" id="transAmtField"/
$(document).ready(function() {
restrictInt(14,3);
});
var oldAmount;
function restrictInt(num,decimal) {
var amount;
var newNum=0;
$("#transAmtField").bind('keyup', function(e) {
amount = $("#transAmtField").val();
if(isNaN(amount)) {
$("#transAmtField").val(amount.replace(/[^0-9\.]/g,''));
return false;
}
if(amount.lastIndexOf(".") != -1) {
if(amount.length-amount.lastIndexOf(".") > decimal+1 ){
$("#transAmtField").val(oldAmount);
return false;
} else if(amount.length <= num+1) {
oldAmount = amount;
return true;
} else {
oldAmount = amount.substring(0,num+1);
$("#transAmtField").val(oldAmount);
return false;
}
}
if(amount.lastIndexOf(".") == -1) {
if(amount.length <= num) {
return true;
} else {
oldAmount = amount.substring(0,num);
$("#transAmtField").val(oldAmount);
return false;
}
}
});
}
Thursday, October 8, 2009
Restrict to number Input box using JQuery
We can use following JQuery code to allow only number in input box :
$('#inputId').bind('keypress', function(e) { return ( e.which!=8 && e.which!=0 && (e.which<48
e.which>57)) ? false : true ;})
$('#inputId').bind('keypress', function(e) { return ( e.which!=8 && e.which!=0 && (e.which<48
e.which>57)) ? false : true ;})
Tuesday, September 29, 2009
Best tips to handle JQuery
Visit following site to get the best tips to handle JQuery :
http://www.listelog.com/improve-your-jquery-25-excellent-tips/
http://www.listelog.com/improve-your-jquery-25-excellent-tips/
Monday, September 7, 2009
Select with JQuery
1.Following way we can select any option / value in select using JQuery :
2. Following way we can disable the element :
2. Following way we can disable the element :
Friday, September 4, 2009
Three technology to handle Simple Ajax
Recently I have used 3 technology in one portal project on requirement basis for handling ajax calls , explaining all three ways to make ajax calls here . I found that JQuery is most effective and easy to use :
1. Using native ajax :
3 Using Smart client : Use data source with Json Or XML
isc.DataSource.create({
ID:"contacts",
dataFormat:"json",
dataURL:employee.php",
fields:[
{name:"name"},
{name:"email"},
{name:"organization"},
{name:"phone"},
{name:"street", valueXPath:"address/street" },
{name:"city", valueXPath:"address/city" },
{name:"state", valueXPath:"address/state"},
{name:"zip", valueXPath:"address/zip" }
]
});
1. Using native ajax :
2. Using JQuery ://Do the AJAX callfunction processStateChange() {
if (window.XMLHttpRequest) {
// Non-IE browsers
req = new XMLHttpRequest();
req.onreadystatechange = processStateChange;
try {
req.open("GET", url, true);
} catch (e) {
alert("Server Communication Problem\n"+e);
}
req.send(null);
} else if (window.ActiveXObject) {
// IE
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange=processStateChange;
req.open("GET", url, true);
req.send();
}
}
if (req.readyState == 4) { // Complete
if (req.status == 200) { // OK response
//Split the text response into Span elements
spanElements =
splitTextIntoSpan(req.responseText);
//Use these span elements to update the page
replaceExistingWithNewHtml(spanElements);
} else {
alert("Problem with server response:\n "
+ req.statusText);
}
}
}
$.ajax({
type: "POST",
url: "some.php",
data: "name=John&location=Boston",
success: function(msg){
alert( "Data Saved: " + msg );
},
error : function() {}
});
3 Using Smart client : Use data source with Json Or XML
isc.DataSource.create({
ID:"contacts",
dataFormat:"json",
dataURL:employee.php",
fields:[
{name:"name"},
{name:"email"},
{name:"organization"},
{name:"phone"},
{name:"street", valueXPath:"address/street" },
{name:"city", valueXPath:"address/city" },
{name:"state", valueXPath:"address/state"},
{name:"zip", valueXPath:"address/zip" }
]
});
Subscribe to:
Posts (Atom)
Popular Posts
-
I had encountered issue while added theme-chalk into scss. It was not loading on the browser. Following line added in scss file and it...
-
Communication of nodes in SAP commerce(Hybris) environment was failing in cluster with following error: INFO | jvm 1 | main | 2020/0...
-
If each of your microservices is containerized using Docker, you can use Docker Compose to define and run all of your services in one go. T...
-
< c:if test="${param.name != null}">< /c:if> The above tag is to check whether parameter name is null or not. If i...