Showing posts with label Js. Show all posts
Showing posts with label Js. Show all posts

Tuesday, January 3, 2017

Cross domain security error dwr

You can avoid security checking in client side in dwr by adding following code into web.xml file

<servlet>
<servlet-name>dwr-invoker</servlet-name>
    <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
        <init-param>
           <param-name>debug</param-name>
           <param-value>false</param-value>
        </init-param>
        <init-param>
           <param-name>accessLogLevel</param-name>
          <param-value>EXCEPTION</param-value>
        </init-param>
        <init-param>
          <param-name>crossDomainSessionSecurity</param-name>
          <param-value>false</param-value>
        </init-param>
</servlet>

Thursday, April 25, 2013

Validate email address in JS

Following java script function can be used to check email validation.

function checkEmail() {        

var email = document.getElementById('txtEmail');      

  var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;        
   if (!filter.test(email.value)) {      
   alert('Please provide a valid email address');      
   email.focus;      
   return false;   
}

Tuesday, October 26, 2010

Get map for latitude & longitude using Google Maps API

Google provides a FREE Java Script map API for longitude & latitude. Simple demonstration is given below. Position marker, mouse wheel zooming, Map view/Satelite view/Hybrid view controls are enabled in the example.

NOTE :- Map searching is commented.

<html>
<head>
<script type="text/javascript"
src="http://www.google.com/jsapi?key=ABCDEFG"></script>
<script type="text/javascript">
google.load("maps", "2");
// google.load("search", "1");
// Call this function when the page has been loaded

function initialize() {
var map = new google.maps.Map2(document.getElementById("map"));
map.setCenter(new google.maps.LatLng(7, 80), 13);
map.enableRotation();
map.addControl(new GOverviewMapControl());
map.enableDoubleClickZoom();
map.enableScrollWheelZoom();
map.addControl(new GMapTypeControl());

map.addControl(new GSmallMapControl());

var marker = new GMarker(new GLatLng(7, 80));
map.addOverlay(marker);
map.setMapType(G_SATELLITE_MAP);

// var searchControl = new google.search.SearchControl();
// searchControl.addSearcher(new google.search.WebSearch());
// searchControl.addSearcher(new google.search.NewsSearch());
// searchControl.draw(document.getElementById("searchcontrol"));
}

google.setOnLoadCallback(initialize);
</script>
</head>
<body>
<div id="map" style="width: 500px; height: 500px"></div>
<!-- <div id="searchcontrol"></div> -->
</body>
</html>

Reference :- http://code.google.com/apis/ajax/documentation/ 

Tuesday, July 6, 2010

From date < To date validate using js

Use the below js code to validate date "From date < To date"

         var frmDate = document.getElementById("frmDate").value;
         var toDate = document.getElementById("toDate").value;

         if (frmDate < toDate) {
               alert("Invalid Date Range!\nStart Date cannot be after End Date!")
               return false;
           }

Sunday, May 2, 2010

Type Cast in Java Script

In js, variables are created as var type. That means, js engine can cast it to the original type by itself.

parseInt(12) will be converted 12 to an Integer value.

           Example                           Result 
parseInt("12")                          12
parseInt("12.657")                    12
parseInt("12aaaa")                   12
parseInt("aaaa")                NaN (means "Not a Number")

Friday, December 11, 2009

Disable enter key using java script

Use the below code to disable enter key. You can also used this to disable un wanted keys,too. Just add more combination of keys after "evt.keyCode == 13".
<html>
<head>
<script language=javascript type=text/javascript>
<!--
function stopRKey(evt) {
var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
if (evt.keyCode == 13) {return false;}
}

document.onkeypress = stopRKey;
-->
</script>
</head>

<body>
<textarea rows="5"></textarea>
</body>
</html>

Tuesday, October 20, 2009

Clear clipboad using java script

Call this java script method to clear your clipboard in IE6. Sorry, it doesn't work in Mozilla and other browsers.

function clsClipsBrd(){
clipboardData.clearData();
}

Monday, August 31, 2009

Get radio button value in js

Suppose your radio button grop is "radiogroup".
function getradioSelection() {
var group=document.getElementsByName("radiogroup");
var grp='';
for(var k=0;k<group.length;k++){
if(group[k].checked){
grp=group[k].value;
}
return grp;
}

This method will return the selected radio button value.

Friday, June 26, 2009

Disable back button in IE using js

use this code in your page onload method.

window.history.forward(1);

Thursday, April 16, 2009

Formatting text on Textarea/ Remove unwanted chars in Textarea

function escapeVal(textarea,replaceWith){

textarea.value = escape(textarea.value);

for(i=0; i<textarea.value.length; i++){

if(textarea.value.indexOf("%0D%0A") > -1){

textarea.value=textarea.value.replace("%0D%0A",replaceWith)

}

else if(textarea.value.indexOf("%0A") > -1){

textarea.value=textarea.value.replace("%0A",replaceWith)

}

else if(textarea.value.indexOf("%0D") > -1){

textarea.value=textarea.value.replace("%0D",replaceWith)

}

}

return unescape(textarea.value);

}


If you need to remove un wanted chars in a textarea you can use the above java script.

parameters
----------

set the textarea object as the 1st parameter and 2nd paramter is the replaceable char with unwanted ones.

Sunday, November 9, 2008

How to validate date using js

function getValidateDate(){
var tmp=true;

var strFrom=document.getElementById("txtFrom").value;
var strTo=document.getElementById("txtTo").value;

if(strFrom!='' && strTo!=''){
var fdate=strFrom.split('-');

var tdate=strTo.split('-');

var strFDate=new Date();
strFDate.setFullYear(fdate[0],fdate[1],fdate[2]);

var strTDate=new Date();
strTDate.setFullYear(tdate[0],tdate[1],tdate[2]);

if(strTDate<strFDate){
alert(strFrom +" is after "+ strTo);
tmp=false;
}
}else{
alert("Date period must be filled");
tmp=false;
}

return tmp;
}


call the getValidateDate() method as follows in the form.

onsubmit="return getValidateDate()"