Hi All,

The following is a script ive found that lets me type something in and it reads from an array using ajax GET.

What im wanting to do is to not require a user to input anything but instead just immediatly call the information from the fixed value that i pass in.

Just like with php, i send a get parameter and it actions that, but i just dont want a click

<html>
<head>
<script type="text/javascript">
function showHint(str)
{
if (str.length==0)
  { 
  document.getElementById("txtHint").innerHTML="";
  return;
  }
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","gethint.asp?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>

<h3>Start typing a name in the input field below:</h3>
<form action=""> 
First name: <input type="text" id="txt1" onkeyup="showHint(this.value)" />
</form>
<p>Suggestions: <span id="txtHint"></span></p> 

</body>
</html>
<html>
<head>
<script type="text/javascript">
function showHint(str)
{
  // Remove this because you want to allow empty string
  //if (str.length == 0)
  //{ 
  //  document.getElementById("txtHint").innerHTML = "";
  //  return;
  //}

  if (window.XMLHttpRequest)
    xmlhttp = new XMLHttpRequest();
  else
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

  xmlhttp.onreadystatechange = function()
  {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
      document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
  };
  xmlhttp.open("GET", "gethint.asp?q=" + str, true);
  xmlhttp.send(null);
}
</script>
</head>
<body>

<h3>Start typing a name in the input field below:</h3>
<form action=""> 
First name: <input type="text" id="txt1" onkeyup="showHint(this.value);" />
</form>
<p>Suggestions: <span id="txtHint"></span></p> 

</body>
</html>

<script type="text/javascript">
// Send the first AJAX request when the page loads.
//
// Alternatively, you can add an onload attribute to body tag and call showHint
// function from there.
//   <body onload="showHint('');">

showHint("");
</script>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.