tags:

views:

106

answers:

0

Sir could you help me to speed up the posting and retrival of recoord from Html to MySql and vice versa following is the Php coding

Thoug it is working but is very slow

var strtopictype,strtopicstatus
var indxtopictype;
var indxtopicstatus;
var indxchostopic
var msgid;

var rindx;
var loc;
var indx
var topid;

//document.getElementById('txttopicid').value=document.getElementById('cmbTopic').options[indx].value

var xmlHttp
var flag;
var flg;

function addRecipient()
{

 var indxrecp=document.getElementById('cmbRecp').selectedIndex;
 var recpId=document.getElementById('cmbRecp').options[indxrecp].value
 var recpnam=document.getElementById('cmbRecp').options[indxrecp].text

 var l=document.getElementById("cmbselRecp").options.length
 var flg=0


if(indxrecp >= 0)
{
 // Create an Option object        

        var opt = document.createElement("option");
        opt.text =  recpnam;
        opt.value = recpId;

// Add an Option object to Drop Down/List Box

 for(flg=0,i=0;i<l;i++)
 {

   if(document.getElementById("cmbselRecp").options[i].value==recpId)
   {
    flg=1
    break;
   }
 }

 if(flg==0)
 {
  document.getElementById("cmbselRecp").options.add(opt);
  //document.getElementById("txtselrecp").value=
  //document.getElementById("txtselrecp").value + opt.value + "," + opt.text +","


 }
 else
 {
  alert("already Exist")
 }
}
else
{
document.getElementById("repErr").innerHTML="please First Select The recepients from  LEFT List";
}
}


function getusername()
{

 xmlHttpusrname=GetXmlHttpObject();

 if (xmlHttpusrname==null)
   {
  alert ("Your browser does not support AJAX!");
  return;
   }

 var url="login.php";
 url=url+"?xxx=dd";
 url=url+"&sid="+Math.random();
 xmlHttpusrname.onreadystatechange=getusernames;

 xmlHttpusrname.open("GET",url,false);

 //alert("USER" +url);

 xmlHttpusrname.send(null);

}
function getusernames()
{ 

 if (xmlHttpusrname.readyState==4)
 {
  st=xmlHttpusrname.responseText;
  //alert(st)
  document.getElementById('unam').innerHTML="FROM SESSION <br>" +st;

 } 



}

function removeRecp()
{


 idx=document.getElementById("cmbselRecp").selectedIndex

 if(idx>=0)
 {
 document.getElementById("cmbselRecp").remove(idx)
 document.getElementById("repErr").innerHTML=""
 }
 else
 {
 document.getElementById("repErr").innerHTML="please Select The recepients from RIGHT List";
 }


}


function chkuser()
{



 xmlHttpusr=GetXmlHttpObject();
 if (xmlHttpusr==null)
   {
  alert ("Your browser does not support AJAX!");
  return;
   }
var userid;
var password;

userid=document.getElementById('txtloginid').value
password=document.getElementById('txtpassword').value


 var url="login.php";
 url=url+"?userid="+userid + "&pwd=" + password;
 url=url+"&sid="+Math.random();
 xmlHttpusr.onreadystatechange=chkusers;

 xmlHttpusr.open("GET",url,false);

 //alert("USER" +url);

 xmlHttpusr.send(null);


}

function chkusers()
{


 if (xmlHttpusr.readyState==4)
 {
  st=xmlHttp.responseText;
  ar=st.split(",")

  if(ar[1]==1)
  {
  d=window.open('postmessage.html?name=' +ar[0],'_self');

  }
  else
  {

  document.getElementById('errmsg').innerHTML=st;


  }



 }

}


function createtopic()
{

var idx1
var idx2

 if(document.getElementById('btnnt').value=="New Topic")
 {

 document.getElementById("crttopic").style.visibility = "visible";
 document.getElementById("chostp").style.visibility='hidden'
 document.getElementById('btnnt').value="Save Topic";
 }
 else
 {
 idx1= document.getElementById("cmbTopicStatus").selectedIndex
 idx2=document.getElementById("cmbTopicType").selectedIndex
 tsat=document.getElementById("cmbTopicStatus").options[idx1].value
        ttype=document.getElementById("cmbTopicType").options[idx2].value;
 topic=document.getElementById("txtnt").value;

 createnewtopic(tsat,ttype,topic);

 document.getElementById("crttopic").style.visibility = "hidden";
 document.getElementById("chostp").style.visibility='visible'
 document.getElementById('btnnt').value="New Topic";

 }

}

function createnewtopic(tsat,ttype,topic)
{
      xmlHttpNT=GetXmlHttpObject();

      if (xmlHttpNT==null)
   {
   alert ("Your browser does not support AJAX!");
     return;
   }

 var url="createtopic.php";
 url=url+"?stat=" +tsat +"&topic= "+topic + "&type=" +ttype;
 url=url+"&sid="+Math.random();


 xmlHttpNT.onreadystatechange=createnewtopics;
 xmlHttpNT.open("GET",url,false);
 xmlHttpNT.send(null);

}

function createnewtopics() 
{ 

  if (xmlHttpNT.readyState==4)
  {
   st=xmlHttpNT.responseText;

  }


}


function filltopictype()
{

 //alert('In Fill Topic 1') 
 xmlHttp1=GetXmlHttpObject();

 if (xmlHttp1==null)
   {
   alert ("Your browser does not support AJAX!");
   return;
   }

 var url="topictypes.php";
 url=url+"?temp=f";
 url=url+"&sid="+Math.random();

 xmlHttp1.onreadystatechange=filltopictypes;
 xmlHttp1.open("GET",url,false);
 xmlHttp1.send(null);


}


function filltopictypes() 
{ 




  if (xmlHttp1.readyState==4)
  {
                     //    alert('In Fill Topic 2')
   st=xmlHttp1.responseText;

   //alert("topic Type" +st)

   fillcombotype(st);
  }



}


function fillcombotype(st)
{

arst= st.split(",");
lenttype =arst.length


 for(i=0;i<lenttype-1;i++)
 {
  var opt = document.createElement("option");
  arval=arst[i].split("*"); 

         opt.value = arval[0]; 
         opt.text =  arval[1];

  //alert(opt.text)
  //alert(opt.value)

  document.getElementById("cmbTopicType").options.add(opt);
 }

document.getElementById("cmbTopicType").selectedIndex=0
//alert('Status ' + xmlHttp1.status)
fillchoosetopic();
}


function fillchoosetopic()
{ 


st="";
idx=ttype=document.getElementById('cmbTopicType').selectedIndex;

ttype=document.getElementById('cmbTopicType').options[idx].text


 //alert('Fill Choose Topic 1' +ttype)

        xmlHttp=GetXmlHttpObject();

 if (xmlHttp==null)
   {
   alert ("Your browser does not support AJAX!");
    return;
   }

 var url="choosetopics.php";
 url=url+"?ttype="+ttype;
 //url=url+"?sql="+sql;

        url=url+"&sid="+Math.random();

 xmlHttp.onreadystatechange=fillchoosetopics;

 xmlHttp.open("GET",url,false);
 xmlHttp.send(null);
}

function fillchoosetopics() 
{

 //alert('Fill Choose Topic 3AA' + st) 
 if (xmlHttp.readyState==4)
 {

 //alert('Fill Choose Topic 3A' + st)
  st=xmlHttp.responseText;



  fillcmbchosetopic(st);



 }

}

function fillcmbchosetopic(st)
{



document.getElementById('cmbTopic').options.length = 0



arst= st.split(",");
lenttype =arst.length

//id='cmbTopic'

// Create an Option object        


 for(i=0;i<lenttype-1;i++)
 {
  var opt = document.createElement("option");
  arval=arst[i].split("*"); 

         opt.value = arval[0]; 
         opt.text =  arval[1];

  //alert(opt.text)
  //alert(opt.value)

  document.getElementById("cmbTopic").options.add(opt);
 }

document.getElementById("cmbTopic").selectedIndex=0

idx=document.getElementById("cmbTopic").selectedIndex
 if (idx >= 0)
 {
     topicid=document.getElementById("cmbTopic").options[idx].value;
  fillselrecipient(topicid)
 }

}


function fillrecipient()
{

 xmlHttp2=GetXmlHttpObject();

 if (xmlHttp2==null)
   {
  alert ("Your browser does not support AJAX!");
  return;
   }



 var url="recipients.php";
 url=url+"?temp=r";
 url=url+"&sid="+Math.random();
 xmlHttp2.onreadystatechange=fillrecipients;

 xmlHttp2.open("GET",url,false);



 xmlHttp2.send(null);


}

function fillrecipients()
{


 if (xmlHttp2.readyState==4)
 {

  document.getElementById("recp").innerHTML=xmlHttp2.responseText;



 }




}


function fillselrecipient(tid)
{ 

 //alert("SEL RECP" +tid)

 xmlHttp3=GetXmlHttpObject();

 if (xmlHttp3==null)
   {
   alert ("Your browser does not support AJAX!");
   return;
   }

 var url="selrecepients.php";
 url=url+"?topicid="+tid;
 url=url+"&sid="+Math.random();
 xmlHttp3.onreadystatechange=fillselrecipients;


 xmlHttp3.open("GET",url,false);
 xmlHttp3.send(null);
}

function fillselrecipients() 
{

 var opt = document.createElement("option");
        //opt.text =  tt;
 //opt.value = dd;
 if (xmlHttp3.readyState==4)
 {

  document.getElementById('srp').innerHTML=xmlHttp3.responseText
  //alert(document.getElementById("srp").innerHTML=xmlHttp3.responseText)

 }

}




function getmsg()
{

topicid=0

idx1=document.getElementById('cmbTopicType').selectedIndex; 
idx2=document.getElementById('cmbTopic').selectedIndex;



if(idx1 >=0 && idx2 >=0)
{

ttype=document.getElementById('cmbTopicType').options[idx1].value
topicid=document.getElementById('cmbTopic').options[idx2].value




 xmlHttp4=GetXmlHttpObject();


 if (xmlHttp4==null)
   {
   alert ("Your browser does not support AJAX!");
   return;
   }

 var url="getsendmsg.php";
 url=url+"?tpid="+topicid +"&ttyp="+ttype;
 url=url+"&sid="+Math.random();

 xmlHttp4.onreadystatechange=setmsgs;


 xmlHttp4.open("GET",url,false);

 xmlHttp4.send(null);
}
else
{

document.getElementById('msgblock').innerHTML="No Message History";
}


}


function setmsgs() 
{

 if (xmlHttp4.readyState==4)
 {


  msg=xmlHttp4.responseText 
  armsg=msg.split("</table>")

  document.getElementById('msgblock').innerHTML=armsg[0];
  document.getElementById('currmsg').innerHTML=armsg[1];




 }

}


function sendMsg()
{


 xmlHttpsnd=GetXmlHttpObject();


 if (xmlHttpsnd==null)
   {
   alert ("Your browser does not support AJAX!");
   return;
   }

 topicid=document.getElementById('cmbTopic').value
 stmsg=document.getElementById('txtMsg').value
 ttype=document.getElementById('cmbTopicType').value

 var parm="&topicid=" +topicid +"&topictype="+ttype  +"&messag="+stmsg;


 var aruid= new Array();
 len =document.getElementById('cmbselRecp').length

 for(j=0;j<len;j++)
 {
  aruid[j]=document.getElementById('cmbselRecp').options[j].value;
 }

 var url="getsendmsg.php?";
 url=url+parm +"&uids=" + aruid +"&sid="+Math.random();

 //alert(url)

 xmlHttpsnd.open("GET",url,false);

 //xmlHttpsnd.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
 //xmlHttpsnd.setRequestHeader("Content-length", parm.length);
 //xmlHttpsnd.setRequestHeader("Connection", "close");

 xmlHttpsnd.onreadystatechange=sendMsgs;
 xmlHttpsnd.send(null);




}

function sendMsgs()
{



 if (xmlHttpsnd.readyState == 4)
 {
  //alert('Great3')
  document.getElementById('cmsg').innerHTML=xmlHttpsnd.responseText; ;
  //alert(xmlHttpsnd.responseText);


  document.getElementById('txtMsg').value=""
  getmsg()

 }


}


function uplaodfile()
{

xmlHttpupload =GetXmlHttpObject();

//alert('load')
//MAX_FILE_SIZE
url="uploader.php";
parm=document.getElementById('fileoad');


xmlHttpupload.open("POST",url,false);
xmlHttpupload.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttpupload.setRequestHeader("Content-length", parm.length);
xmlHttpupload.setRequestHeader("Connection", "close");


xmlHttpupload.onreadystatechange=uploadfiles();
xmlHttpupload.send(parm)

}


function uploadfiles()
{
//alert('load 2')
//alert(xmlHttpupload.readyState)
if (xmlHttpupload.readyState == 1)
 {
  //alert('Great3')
  //document.getElementById('cmsg').innerHTML=xmlHttpsnd.responseText; ;
  //alert(xmlHttpupload.responseText);
  document.getElementById('ldmsg').value=xmlHttpupload.responseText;


 }

}


function GetXmlHttpObject()
{

 try
   {
   // Firefox, Opera 8.0+, Safari
   xmlHttp=new XMLHttpRequest();
   }
 catch (e)
   {
   // Internet Explorer
   try
     {
     xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
     }
   catch (e)
     {
     xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
     }
   }
 return xmlHttp;
}