Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating table inside div

 
carina caoor
Ranch Hand
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi i want to create a table inside the div element where in this table i can display the xml read along with a radio button.
my js file is


if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{

var alength=xmlHttp.responseXML.getElementsByTagName("areacode");
for(i=0;i<alength.length;i++)
{
var message = xmlHttp.responseXML.getElementsByTagName("areacode")[i].childNodes[0].nodeValue;

document.getElementById('displayareacode').innerHTML="<tr><td><input type='radio' name='plotnoradio' value='"+message+"'>"+message+"</td></tr>";
}


document.getElementById('displayareacode').innerHTML="</table>";
}

please suggest me how do i create a table here in div element named as 'displayareacode'.
 
Stoyan Stefanov
author
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is it just that you're missing the opening <table> tag, before the for-loop, something like:
document.getElementById('displayareacode').innerHTML="<table>";
 
Santoshkumar Jeevan Pawar
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, its you are missing only table opening tag, otherwise it should work fine.

Thank You.
Have a Nice Time.

-Santosh
 
carina caoor
Ranch Hand
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actually i missed to print it here its there in my code, my problem is i have a servlet generating xml file
<?xml version="1.0" encoding="ISO-8859-1" ?>
<parent>
<areacode>00/000/00</areacode>
<areacode>40/111/00</areacode>
<areacode>30/99/20</areacode>
<areacode>10/090/50</areacode>
<areacode>50/060/00</areacode>
<areacode>80/600/05</areacode>
</parent>
using ajax xmlHttp object i am reading this xml file
i have a text input field whenever i enter a number it makes ajaxcalls
if i enter 00 in text input field it should display the areacodes that have zeros in it in the div tag.
i.e
00/000/00
40/111/00
50/060/00
but here it is not displaying all the three values it just displaying only one value that is 50/060/00.

My .js file contains the code:-

for(i=0;i<alength.length;i++)
{
var message= new array(alength.length);
message[i]=xmlHttp.responseXML.getElementsByTagName("areacode")[i].childNodes[0].nodeValue;

//also i am trying to print the read value in the div tag
document.getElementById('displayareacode').innerHTML=message[i];
}

i dont want to overwrite the values they should be one below the other
Like this:- Based on search criteria.

00/000/00
40/111/00
30/99/20
10/090/50
50/060/00
80/600/05


please help.
 
Santoshkumar Jeevan Pawar
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi just use following script it should work, i have written for you.

Thank You.
Have a Nice Time.

-Santosh




var parentNodes = xmlHttp.responseXML.getElementsByTagName("parent");
var inHtml;
for (var j=0; j<parentNodes.length; j++) {

var nameNodes = parentNodes[j].getElementsByTagName("areacode");
var tempareacode = areacodeNodes[0].firstChild.nodeValue;
message[i]=tempareacode;
inHtml=inHtml+tempareacode;
}
document.getElementById('displayareacode').innerHTML=inHtml;
 
carina caoor
Ranch Hand
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey thanks for that i could manage to get it by trial and error & the resulted script i have written is
if(xmlHttp.readyState==4)
{

var zeTable = "<table>";

document.myForm.time.value=xmlHttp.responseText;

document.myForm.avplots.value=xmlHttp.responseText;
var alength=xmlHttp.responseXML.getElementsByTagName("areacode");
for(i=0;i<alength.length;i++)
{

var m=new Array(alength.length);
m[i]=xmlHttp.responseXML.getElementsByTagName("areacode")[i].childNodes[0].nodeValue;
zeTable =zeTable+"<tr><td><input type='radio' name='areacoderadio' value='"+m[i]+"'>"+m[i]+"</td></tr>";



}
zeTable=zeTable+"</table>";
document.getElementById('show').innerHTML=zeTable;
// document.getElementById('show').innerHTML="</tr></table>";
}

and its working
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic