Search This Blog

Saturday 19 July 2014

javascript

Ajax Request  Submit
================
var request_param_name value = “some_value”;
$.ajax({ url: "struts2actionurl",
         data: "request_param_name=" + request_param_name value,
          success: function(data) {   
          document.getElementById('divId').innerHTML = data;
         }
});



Java Script function to restrict the keys in textbox except number
==================================================
Javacsript:

function isNumber(evt) {
    evt = (evt) ? evt : window.event;
    var charCode = (evt.which) ? evt.which : evt.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        return false;
    }
    return true;
}
Java script alpha numeric check
============================================

function alphanumericCheck(alphane) {
    var numaric = alphane;
    for (var j = 0; j < numaric.length; j++) {
        var alphaa = numaric.charAt(j);
        var hh = alphaa.charCodeAt(0);
        // if (j == 0) {
        if ((hh > 64 && hh < 91) || (hh > 96 && hh < 123) || (hh > 47 && hh < 58) || (hh == 32) || (hh == 45)) {

        } else {
            return false;
        }
    }
    return true;
}

Numeric check:
=================================================
function numericCheck(numericData) {
    var numaric = numericData;
    var periodCount = 0;
    for (var j = 0; j < numaric.length; j++) {
        var alphaa = numaric.charAt(j);
        var hh = alphaa.charCodeAt(0);
        if ((hh > 47 && hh < 58) || hh == 46) {
            if (hh == 46) {
                periodCount += 1;
                if (periodCount > 1) {
                    return false;
                }
            }
        } else {
            return false;
        }
    }
    return true;
}

Java script checking null, empty and undefined
===========================================================
Var jsVar = document.getElementById('htmlObjectId').value;
    if (jsVar!= null && jsVar!= "" && jsVar!= undefined) {
//java script if body
}
In jsp:

<input type="text" id="refine" onkeypress="return isNumber(event)"/>

Submitting post request through javascript
========================================================

      var method = "POST";
        var form = document.createElement("form");
        form.setAttribute("method", method);
        form.setAttribute("action", "request_action_url.action");

        var hiddenField = document.createElement("input");
        hiddenField.setAttribute("type", "hidden");
        hiddenField.setAttribute("name", "param_name");
        hiddenField.setAttribute("value", value);
        form.appendChild(hiddenField);
       document.body.appendChild(form);
       form.submit();


showing progress bar
===================================
        $("#lock_divId").addClass("lock_class");
        $("body").addClass("lockBody_class");
        $("#progressbarDivId").show();
       $.ajax({
            url: "request_action_url",
            data: parameters,
            cache: false,
            success: function (data) {
                document.getElementById('result_divId').innerHTML = data;
                document.getElementById('result_divId').style.display = "block";
                $("# lock_divId").removeClass("lock");
                $("body").removeClass("lockBody_class ");
                $("#progressbarDivId ").hide("slow");
}
});
.lockBody{overflow: hidden;}

Changing html table row color through javascript
=====================================
var html_table = document.getElementById("html_table_name"); 
if(table != null){
var html_table_body = html_table.getElementsByTagName("tbody")[0];
if(html_table_body != null){
var html_table_rows = html_table_body.getElementsByTagName("tr");
if(html_table_rows != null){
var blueRowColor = document.getElementById("blueRowColor").value;
var redRowColor = document.getElementById("redRowColor").value;
var greenRowColor = document.getElementById("greenRowColor").value;
// add event handlers so rows light up and are clickable
for (i=0; i < html_table_rows.length; i++) {
    var tds = html_table_rows[i].getElementsByTagName("td");
    var tdsLength=tds.length;
    if (tds[1].innerHTML == "Red") {
        for ( var int = 0; int < tdsLength ; int++) {
            tds[int].style.color = redRowColor;           
        }
    } else if(tds[1].innerHTML == "blue") {
        for ( var int = 0; int < tdsLength ; int++) {
            tds[int].style.color = blueRowColor;           
        }
    } else if(tds[1].innerHTML == "green") {
        for ( var int = 0; int < tdsLength ; int++) {
            tds[int].style.color = greenRowColor;           
        }
    }
}
}}}

No comments:

Post a Comment