...

View Full Version : Ajax with xml



Fot
04-11-2011, 04:03 PM
I have a problem because I cannot use background-color in a column from table with many columns.I would like advice.Thanks. I use this code:

function loadh(url)
{
var xmlhttp;
var txt,xx,x,i;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
txt="<table border='1'><tr><th>County_UA</th><th>Pop_code</th></tr>";
x=xmlhttp.responseXML.documentElement.getElementsByTagName("Data");
for (i=140;i<x.length;i++)
{
txt=txt + "<tr>";
xx=x[i].getElementsByTagName("County_UA");
{
try
{
txt=txt + "<td>" + xx[0].firstChild.nodeValue + "</td>";
}
catch (er)
{
txt=txt + "<td>&nbsp;</td>";
}
}
xx=x[i].getElementsByTagName("Pop_code");
{
try
{
txt=txt + "<td>" + xx[0].firstChild.nodeValue + "</td>";
}
catch (er)
{
txt=txt + "<td>&nbsp;</td>";
}
}
txt=txt + "</tr>";
}
txt=txt + "</table>";
document.getElementById('ellas').innerHTML=txt;
}
}
xmlhttp.open("GET",url,true);
xmlhttp.send();
}

oesxyl
04-11-2011, 04:22 PM
I have a problem because I cannot use background-color in a column from table with many columns.I would like advice.
why you can't use background-color?
one way to do this is here:

http://www.htmldog.com/guides/htmladvanced/tables/

another way is to add a inline style to the td from that column

maybe oftopic, border='1' could be invalid but this depend of your doctype

best regards

Fot
04-11-2011, 05:07 PM
Thanks , also I would like to learn in the same code to be sorted by one or two fields with or without xsl.

oesxyl
04-11-2011, 05:12 PM
Thanks , also I would like to learn in the same code to be sorted by one or two fields with or without xsl.
you are welcome, :) you can learn both, :) a good idea if you want to start to learn/use xsl is to learn xpath.

best regards

Fot
04-11-2011, 06:43 PM
Thanks.Do you know any way to reload my page when load with ajax data from xml because with every click on drop down list I have a display with previous and the every click data .

oesxyl
04-11-2011, 06:52 PM
Thanks.Do you know any way to reload my page when load with ajax data from xml because with every click on drop down list I have a display with previous and the every click data .
you can use reload:

http://www.javascriptkit.com/jsref/location.shtml

but i dont understand what you do and why do you need to reload the page.
if i'm not wrong and you want to refresh some information in the page after you change the state of a drop down list you can use an event attached to the drop down list, for exmple the onchange event. But you need to write a function to refresh the information according to the changes.

best regards

Fot
04-11-2011, 07:04 PM
The reason is because it is not possible as I have different functions and I cannot use onchange.Do you know other way to refresh my page and references for the proper function.Thanks.

<option value="">Select fields:</option>
<option onclick="loadXMLDoc('w.xml')" value="3">3</option>
<option onclick="loadm('w.xml')" value="all">all</option>
</select>

oesxyl
04-11-2011, 08:03 PM
The reason is because it is not possible as I have different functions and I cannot use onchange.Do you know other way to refresh my page and references for the proper function.Thanks.

<option value="">Select fields:</option>
<option onclick="loadXMLDoc('w.xml')" value="3">3</option>
<option onclick="loadm('w.xml')" value="all">all</option>
</select>
you can call this functions inside the onchange event based of selection. As far as i see both have same argument, w.xml, so maybe another alternative is to rewrite the code based on selection.

best regards

Fot
04-12-2011, 10:48 PM
Hello, I would like help as I have a different problem with ajax and xml.The problem is that I want to display presidents information with photos by writing the year in a textbox.I try with the code below but cannot load the xml.Thanks

<html>
<head>
<title>Lookup Form</title>
<link href="Lookup.css" type="text/css" rel="stylesheet"/>
<script type="text/javascript">
function Lookup(FORM)
{
var year = FORM.Year.value;
if (isNaN(year) || year.length != 4)
{
alert("Please enter a valid year.");
return false;
}


}


</script>
</head>
<body>

<form id="LookupForm" onsubmit="Lookup(this); return false;">
<h1>Lookup Form</h1>
<p>Enter a year between 1789 and 1845 to find out who was president that year.</p>
<div class="FormRow">
<label for="Year">Year:</label>
<input type="text" size="5" id="Year" name="Year"/>
<input type="submit" value="Lookup"/>
</div>
<hr/>
<div class="FormRow" id="LookupResults"></div>
</form>

</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum