Ajax Function

AJAX CODE SAMPLE

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean"	prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html"	prefix="html"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-nested" prefix="nested"%>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c"%>


<%String path = request.getContextPath();
			String basePath = request.getScheme() + "://"
					+ request.getServerName() + ":" + request.getServerPort()
					+ path + "/";
%>


<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<base href="<%=basePath%>">
		
		<link href="<%=basePath%>css/adminConsole.css" rel="stylesheet" type="text/css" />
		
		<script type="text/javascript">
		function clearlistbox(){
		var lb=document.getElementById("dest");
  	for (var i=lb.options.length-1; i>=0; i--){
    lb.options[i] = null;
  }
  lb.selectedIndex = -1;
  var lb_src=document.getElementById("src");
  	for (var i=lb_src.options.length-1; i>=0; i--){
    lb_src.options[i] = null;
  }
  lb_src.selectedIndex = -1;
  
  document.getElementById("appid").options[0].selected=true;
  document.getElementById("pageid").options[0].selected=true;
}
		
		function selectPages(appid)
		{
		
		//alert(appid);
		if (window.XMLHttpRequest) {
			xmlhttp = new XMLHttpRequest();
		} else {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		//alert("1");
		//var url="jsp/permission/test.jsp";
		var url="/IMPS_Subscription/permission.do?page=submitUserPermission&appid="+appid;
		xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState == 1||xmlhttp.readyState == 2||xmlhttp.readyState == 3)
			{
			
			//alert(xmlhttp.status);
			document.getElementById("mydiv").innerHTML="<img src='images/ajax-loader.gif'/>"
			}
			//alert(xmlhttp.status);
			//alert(xmlhttp.readyState);
			//alert("2");
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			
			document.getElementById("mydiv").innerHTML=xmlhttp.responseText;
		    
		    }
		    
			}
			xmlhttp.open("GET",url,true);
			xmlhttp.send();
		}
		
		function selectText(page){
		//alert(page);
		//clearlistbox();
		var username=document.getElementById("username").value;
		//alert("username.."+username);
		var appid=document.getElementById("appid").value;
		//alert("appid.."+appid);
		var pageid=document.getElementById("pageid").value;
		//alert("pageid.."+pageid);
		if (window.XMLHttpRequest) {
			xmlhttp = new XMLHttpRequest();
		} else {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		var url="/IMPS_Subscription/permission.do?page=submitUserPermission&pagename="+page+"&username="+username+"&applicationid="+appid+"&pageid="+pageid;
		xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState == 1||xmlhttp.readyState == 2||xmlhttp.readyState == 3)
			{
			document.getElementById("mydiv_text").innerHTML="<img src='images/ajax-loader.gif'/>"
			}
			
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			document.getElementById("mydiv_text").innerHTML=xmlhttp.responseText;
		    }
		    }
			xmlhttp.open("GET",url,true);
			xmlhttp.send();
		}
		
	function move_to_dest(sourceID, destID) {
    var src = document.getElementById(sourceID);
    var dest = document.getElementById(destID);
 
    for(var count=0; count < src.options.length; count++) {
 
        if(src.options[count].selected == true) {
                var option = src.options[count];
 
                var newOption = document.createElement("option");
                newOption.value = option.value;
                newOption.text = option.text;
                newOption.selected = true;
                try {
                         dest.add(newOption, null); //Standard
                         src.remove(count, null);
                 }catch(error) {
                         dest.add(newOption); // IE only
                         src.remove(count);
                 }
                count--;
        }
    }
}
		
		function move_to_src(sourceID, destID) {
    var src = document.getElementById(sourceID);
    var dest = document.getElementById(destID);
 
    for(var count=0; count < dest.options.length; count++) {
 
        if(dest.options[count].selected == true) {
                var option = dest.options[count];
 
                var newOption = document.createElement("option");
                newOption.value = option.value;
                newOption.text = option.text;
                newOption.selected = true;
                try {
                         src.add(newOption, null); //Standard
                         dest.remove(count, null);
                 }catch(error) {
                         src.add(newOption); // IE only
                         dest.remove(count);
                 }
                count--;
        }
    }
}

		function moveall_to_src(sourceID, destID) {
    var src = document.getElementById(sourceID);
    var dest = document.getElementById(destID);
 
    for(var count=0; count < dest.options.length; count++) {
 
       
                var option = dest.options[count];
 
                var newOption = document.createElement("option");
                newOption.value = option.value;
                newOption.text = option.text;
                newOption.selected = true;
                try {
                         src.add(newOption, null); //Standard
                         dest.remove(count, null);
                 }catch(error) {
                         src.add(newOption); // IE only
                         dest.remove(count);
                 }
                count--;
        
    }
}
function moveall_to_dest(sourceID, destID) {
    var src = document.getElementById(sourceID);
    var dest = document.getElementById(destID);
 
    for(var count=0; count < src.options.length; count++) {
 
        
                var option = src.options[count];
 
                var newOption = document.createElement("option");
                newOption.value = option.value;
                newOption.text = option.text;
                newOption.selected = true;
                try {
                         dest.add(newOption, null); //Standard
                         src.remove(count, null);
                 }catch(error) {
                         dest.add(newOption); // IE only
                         src.remove(count);
                 }
                count--;
        
    }
}

function submitPermission()
{
if(document.getElementById("username").value==0)
		{
		alert("Select User Name");
		return false;
		}else if(document.getElementById("appid").value==0){
		alert("Select Application")
		return false;
		}else if(document.getElementById("pageid").value==0){
		alert("Select Page");
		return false;
		}
//alert("start");
var txtid="";
var list_dest=document.getElementById("dest");
for(var i=0;i<list_dest.options.length;i++){
//alert("inside 4");
//if(list_dest.options[i].selected==true){
txtid=txtid+list_dest.options[i].value+"-";
//alert("inside if")
//}
}
var unrestxtid="";
var list_src=document.getElementById("src");
for(var i=0;i<list_src.options.length;i++){
unrestxtid=unrestxtid+list_src.options[i].value+"-";
}


//alert(txtid);
var pgid=document.getElementById("pageid").value;
var uname=document.getElementById("userna

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean"      prefix="bean"%>

<%@ taglib uri="http://jakarta.apache.org/struts/tags-html"      prefix="html"%>

<%@ taglib uri="http://jakarta.apache.org/struts/tags-nested" prefix="nested"%>

<%@ taglib uri="/WEB-INF/c.tld" prefix="c"%>

 

 

<%String path = request.getContextPath();

                                    String basePath = request.getScheme() + "://"

                                                            + request.getServerName() + ":" + request.getServerPort()

                                                            + path + "/";

%>

 

 

<html>

            <head>

                        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

                        <meta http-equiv="pragma" content="no-cache">

                        <meta http-equiv="cache-control" content="no-cache">

                        <meta http-equiv="expires" content="0">

                        <base href="<%=basePath%>">

                       

                        <link href="<%=basePath%>css/adminConsole.css" rel="stylesheet" type="text/css" />

                       

                        <script type="text/javascript">

                        function clearlistbox(){

                        var lb=document.getElementById("dest");

            for (var i=lb.options.length-1; i>=0; i--){

    lb.options[i] = null;

  }

  lb.selectedIndex = -1;

  var lb_src=document.getElementById("src");

            for (var i=lb_src.options.length-1; i>=0; i--){

    lb_src.options[i] = null;

  }

  lb_src.selectedIndex = -1;

 

  document.getElementById("appid").options[0].selected=true;

  document.getElementById("pageid").options[0].selected=true;

}

                       

                        function selectPages(appid)

                        {

                       

                        //alert(appid);

                        if (window.XMLHttpRequest) {

                                    xmlhttp = new XMLHttpRequest();

                        } else {

                                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

                        }

                        //alert("1");

                        //var url="jsp/permission/test.jsp";

                        var url="/IMPS_Subscription/permission.do?page=submitUserPermission&appid="+appid;

                        xmlhttp.onreadystatechange=function(){

                        if(xmlhttp.readyState == 1||xmlhttp.readyState == 2||xmlhttp.readyState == 3)

                                    {

                                   

                                    //alert(xmlhttp.status);

                                    document.getElementById("mydiv").innerHTML="<img src='images/ajax-loader.gif'/>"

                                    }

                                    //alert(xmlhttp.status);

                                    //alert(xmlhttp.readyState);

                                    //alert("2");

                                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {

                                   

                                    document.getElementById("mydiv").innerHTML=xmlhttp.responseText;

                           

                            }

                           

                                    }

                                    xmlhttp.open("GET",url,true);

                                    xmlhttp.send();

                        }

                       

                        function selectText(page){

                        //alert(page);

                        //clearlistbox();

                        var username=document.getElementById("username").value;

                        //alert("username.."+username);

                        var appid=document.getElementById("appid").value;

                        //alert("appid.."+appid);

                        var pageid=document.getElementById("pageid").value;

                        //alert("pageid.."+pageid);

                        if (window.XMLHttpRequest) {

                                    xmlhttp = new XMLHttpRequest();

                        } else {

                                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

                        }

                        var url="/IMPS_Subscription/permission.do?page=submitUserPermission&pagename="+page+"&username="+username+"&applicationid="+appid+"&pageid="+pageid;

                        xmlhttp.onreadystatechange=function(){

                        if(xmlhttp.readyState == 1||xmlhttp.readyState == 2||xmlhttp.readyState == 3)

                                    {

                                    document.getElementById("mydiv_text").innerHTML="<img src='images/ajax-loader.gif'/>"

                                    }

                                   

                                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {

                                    document.getElementById("mydiv_text").innerHTML=xmlhttp.responseText;

                            }

                            }

                                    xmlhttp.open("GET",url,true);

                                    xmlhttp.send();

                        }

                       

            function move_to_dest(sourceID, destID) {

    var src = document.getElementById(sourceID);

    var dest = document.getElementById(destID);

 

    for(var count=0; count < src.options.length; count++) {

 

        if(src.options[count].selected == true) {

                var option = src.options[count];

 

                var newOption = document.createElement("option");

                newOption.value = option.value;

                newOption.text = option.text;

                newOption.selected = true;

                try {

                         dest.add(newOption, null); //Standard

                         src.remove(count, null);

                 }catch(error) {

                         dest.add(newOption); // IE only

                         src.remove(count);

                 }

                count--;

        }

    }

}

                       

                        function move_to_src(sourceID, destID) {

    var src = document.getElementById(sourceID);

    var dest = document.getElementById(destID);

 

    for(var count=0; count < dest.options.length; count++) {

 

        if(dest.options[count].selected == true) {

                var option = dest.options[count];

 

                var newOption = document.createElement("option");

                newOption.value = option.value;

                newOption.text = option.text;

                newOption.selected = true;

                try {

                         src.add(newOption, null); //Standard

                         dest.remove(count, null);

                 }catch(error) {

                         src.add(newOption); // IE only

                         dest.remove(count);

                 }

                count--;

        }

    }

}

 

                        function moveall_to_src(sourceID, destID) {

    var src = document.getElementById(sourceID);

    var dest = document.getElementById(destID);

 

    for(var count=0; count < dest.options.length; count++) {

 

      

                var option = dest.options[count];

 

                var newOption = document.createElement("option");

                newOption.value = option.value;

                newOption.text = option.text;

                newOption.selected = true;

                try {

                         src.add(newOption, null); //Standard

                         dest.remove(count, null);

                 }catch(error) {

                         src.add(newOption); // IE only

                         dest.remove(count);

                 }

                count--;

       

    }

}

function moveall_to_dest(sourceID, destID) {

    var src = document.getElementById(sourceID);

    var dest = document.getElementById(destID);

 

    for(var count=0; count < src.options.length; count++) {

 

       

                var option = src.options[count];

 

                var newOption = document.createElement("option");

                newOption.value = option.value;

                newOption.text = option.text;

                newOption.selected = true;

                try {

                         dest.add(newOption, null); //Standard

                         src.remove(count, null);

                 }catch(error) {

                         dest.add(newOption); // IE only

                         src.remove(count);

                 }

                count--;

       

    }

}

 

function submitPermission()

{

if(document.getElementById("username").value==0)

                        {

                        alert("Select User Name");

                        return false;

                        }else if(document.getElementById("appid").value==0){

                        alert("Select Application")

                        return false;

                        }else if(document.getElementById("pageid").value==0){

                        alert("Select Page");

                        return false;

                        }

//alert("start");

var txtid="";

var list_dest=document.getElementById("dest");

for(var i=0;i<list_dest.options.length;i++){

//alert("inside 4");

//if(list_dest.options[i].selected==true){

txtid=txtid+list_dest.options[i].value+"-";

//alert("inside if")

//}

}

var unrestxtid="";

var list_src=document.getElementById("src");

for(var i=0;i<list_src.options.length;i++){

unrestxtid=unrestxtid+list_src.options[i].value+"-";

}

 

 

//alert(txtid);

var pgid=document.getElementById("pageid").value;

var uname=document.getElementById("userna

Comments 3 comments

hiiiii 5 years ago

HEyy GREAT


David 5 years ago

How can we use these function


Adi 5 years ago

Thankyou

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working