Forum Moderators: open

Message Too Old, No Replies

onchange select with ajax using forloops

second select dont loops..

         

nanat

5:34 am on Oct 2, 2009 (gmt 0)

10+ Year Member



i trying to create onchange select with for loops..
my ajax function

<script>
function getXMLHTTP() { //fuction to return the xml http object
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 getCity(strURL) {

var req = getXMLHTTP();

if (req) {

req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('mirkado').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}

}
</script>



how can i loop this dom document.getElementById('mirkado')
base on $row = 5;?

this my php query


<?php
$row = 5;
$col = 4;
for ($r=1; $r<=$row; $r++)
{
echo '<table>';
echo '<tr>';
?>
<td width="285" id="info" NOWRAP="NOWRAP">

<table width="285" height="36" border="0">
<tr>
<td width="44" height="30" valign="top">
<select name="Market" onChange="getCity('GetPackType.php?GetMarker='+this.value)">
<option value="<?=$market?>">
<?=$market?>
</option>
<?php
echo selectProduction();
?>
</select></td>
<td width="231" valign="top"><div id="mirkado"></div></td>
</tr>
</table>
</td>
<?

for ($c=1; $c <=$col; $c++)
{

echo'<td><input type="text" size="6" name="col[]"></td>';

}
echo '</tr>';
echo '</table>';
}
?>



my problem is statement doesnt loops <div id="mirkado"></div> but my <select name="Market" > works fine.. T_T

whoisgregg

1:57 pm on Oct 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Three basic changes are required. First, you have to add a number to your <div> that will receive the AJAX result:

<div id="mirkado<?php echo $r; ?>">

Second you have to pass that ID to your javascript function so it knows which row you are working on:

 onChange="getCity('GetPackType.php?GetMarker='+this.value, 'mirkado<?php echo $r; ?>')"> 

Finally, you have to update your function to receive the number parameter and to update the right element:

 function getCity(strURL, elementId) {

... then farther down in that function:
 document.getElementById(elementId).innerHTML=req.responseText; 

nanat

12:52 am on Oct 6, 2009 (gmt 0)

10+ Year Member



tnx gregg asome.. :bow: :bow: