Jump to content

My ajax doesn't work, pls help


ivytony

Recommended Posts

I'm trying to create a webpage that allows users to enter a number first, then corresponding number of text input fields shall be populated underneath the number input field. Below is my code:

 

inputfields.php is responsible for outputing input field(s)

 

<?php

$numrebates=$_GET['number'];
//$numrebates=$_POST['numrebates'];
$fieldnum="1";
//echo $numrebates;
while ($numrebates >= 1) {
$numrebates--;

//$input = "<input=text name= field". $fieldnum. "><br>";
print("<br><input type=\"text\" name=\"field$fieldnum\"><br>");
//print $input;
$fieldnum++;
}
?>

 

 

 

 

 

 

Below is between <body> and </body> in the html file called inputfields.htm

<script language="javascript" type="text/javascript">
var xmlHttp

function showinputs()
{
var number = document.getElementById("number").value;
if ((number == null) || (number == 0)) return;


var url="inputfields.php?number=" number;

// Open a connection to the server
  xmlHttp.open("GET", url, true);

xmlHttp.onreadystatechange=updatepage;

xmlHttp.send(null);
} 




function updatepage() 
{ 
if (xmlHttp.readyState==4)
{ 
if (request.status == 200) {
var response = xmlHttp.responseText;
    document.getElementById("number").value = response;
//document.getElementById("number").value = response[0];

}else
       alert("status is " + request.status);
}
}



function GetXmlHttpObject()
{
var xmlHttp=null;
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;
}
</script>

<form> 
Number of Fields:
<input type="text" name="number" id="number" onChange="showinputs();">
</form>

<p>Input Fields:<span id="number"></span></p> 

 

Right now, my ajax doesn't respond at all. I am wondering where is wrong. I am pretty much a newbie to ajax.

 

Thanks for help!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.