aryan kanwar aryan kanwar - 3 months ago 10
Ajax Question

Table css property not changing after ajax call

Initially my table display is none so its not visible in my application i am using ajax call so when the user selects any option a table is generated and the initiall display property which was set to be none changes to block and it becomes visible but my table is not getting visible.Please suggest.

Ajax works fine its only the display property not getting changed

JAVASCRIPT CODE

function checkbrand(str) {
document.getElementById("first").style.display="block";
if (str == "") {
document.getElementById("brand").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {

xmlhttp = new XMLHttpRequest();
} else {

xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("brand").innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("GET","test1.php?m="+str,true);
xmlhttp.send();
}
}


PHP CODE

<?php
session_start();
require('connect.php');
$m = $_GET['m'];
$skuarray=array();
$p=$_SESSION['Head_item_id'];
$sql="SELECT * FROM `major_item_table` where Head_item_id=$p";
$query=$handler->query($sql);
echo '<select id="category" onchange="checkbrand(this.value)";>';
echo '<option selected="selected">Select SubCategory</option>';
while($r=$query->fetch())
{
echo "<option>". $r['Major_item_name']."</option>";

}
echo '</select>';

echo '<div id="first" style="display:none">';
echo '<table>
<tr>
<th>SKU</th>
<th>Vendor_Id</th>
<th>Rates_Entered</th>
<th>Rate_Shown_On_Website</th>
<th>Date_Time</th>
<th>Rate_Type</th>
</tr>';
echo '</table>';
?>

Answer

Try this:

function checkbrand(str) {
   document.getElementById("first").style.display="block";    
   if (str == "") {
}// End of function

setInterval(function(){checkbrand(str)},1000);//You can pass your argument by yourself

You need to use setInterval. It calls this function after interval of time. Here I have set it for 1 sec. You can try this. Hope It will help you.