I have two text fields which whatever user enters in first text field, it will appear in second one by Ajax. I need to use for loop to have multiple rows and every row have their own value.
HTML
<form style="text-align:center" method="post" action="" name="form1">
<?php for($x=0; $x<4; $x++){ ?>
<input type="text" size="30" id="country" onChange="getCurrencyCode('find_ccode.php?country='+this.value)" />
<input type="text" name="cur_code" id="cur_code" ></p>
Ajax
function getXMLHTTP() {
var xmlhttp=false;
try{
xmlhttp=new XMLHttpRequest();
}
catch(e) {
try{
xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e1){
xmlhttp=false;
}
}
}
return xmlhttp;
}
function getCurrencyCode(strURL)
{
var req = getXMLHTTP();
if (req)
{
req.onreadystatechange = function()
{
if (req.readyState == 4)
{
if (req.status == 200)
{
document.getElementById('cur_code').value=req.responseText;
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
Php
$country=$_REQUEST['country'];
echo $country;
Please help me with it.
Try like this…
javascript function