Wednesday, September 15, 2010

Get all form element through JS

//call the ocg function with inout field action with str = this.form
function ocg(str){
var fname= str.name;
 var elem = str//document.getElementById('str').elements;

 var str1="";
 for(var i = 0; i < elem.length; i++)
 {

 if((elem[i].type=='radio'))
 {
 if(elem[i].checked){
 str1 += elem[i].name;
 str1 +=  elem[i].value ;
 str1 += "##";
  }
  }
  //selected value of select box
if(elem[i].type=='select-one'){
  //str1 +=  elem[i].type ;
  str1 += elem[i].name;
  str1 +=  elem[i].value ;
  str1 += "##";
  }
 }


if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get.php?q="+escape(str1),true);
xmlhttp.send();
}


place the get.php at right location and print str in it

No comments:

Post a Comment