my dog learned polymorphism*
The moose likes HTML, CSS and JavaScript and the fly likes Creating table inside div Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Creating table inside div" Watch "Creating table inside div" New topic
Author

Creating table inside div

carina caoor
Ranch Hand

Joined: Jun 23, 2007
Posts: 300

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

Joined: Jul 16, 2008
Posts: 61
is it just that you're missing the opening <table> tag, before the for-loop, something like:
document.getElementById('displayareacode').innerHTML="<table>";


<a href="http://www.thinkinginjavascript.com" target="_blank" rel="nofollow">my OOJS book</a>
Santoshkumar Jeevan Pawar
Greenhorn

Joined: Aug 19, 2006
Posts: 27
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

Joined: Jun 23, 2007
Posts: 300

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

Joined: Aug 19, 2006
Posts: 27
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

Joined: Jun 23, 2007
Posts: 300

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

Joined: Jan 10, 2002
Posts: 61309
    
  66

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 .


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
GeeCON Prague 2014
 
subject: Creating table inside div