ivytony Posted February 27, 2008 Share Posted February 27, 2008 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! Quote Link to comment Share on other sites More sharing options...
ivytony Posted February 27, 2008 Author Share Posted February 27, 2008 anyone can help me out? :( :( Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.