Saturday 15 January 2011

javascript - Getting Input inside tag within a tbody? -



javascript - Getting Input inside <tr> tag within a tbody? -

just quick question. know has come lot of times , have searched on stack overflow. have created working javascript function tag values within each row of table.

however, when include <tbody> tag (which required row sorting), javascript code not work , have no thought why?

please see code below:

function writexml() { var table = document.getelementbyid('table_assoc'); alert(table); var rcount = document.getelementbyid('tbody_id').rows.length; alert(rcount); var fso = new activexobject("scripting.filesystemobject"); var filename = "c:/xml.xml"; var file = fso.createtextfile(filename, true); file.writeline('<?xml version="1.0" encoding="utf-8"?>\n'); file.writeline('<seating_plan>\n'); (var = 1; < rcount; i++) { var id = table.rows[i].cells[0].children[0].value; <-- cant find table reference when <tbody> tag included. var deptcode = table.rows[i].cells[1].children[0].value; var name = table.rows[i].cells[2].children[0].value; var role = table.rows[i].cells[3].children[0].value; var desc = table.rows[i].cells[4].children[0].value; var image = table.rows[i].cells[5].children[0].value; var asdir = table.rows[i].cells[6].children[0].value; file.writeline('<person id="' + id + '"><dept>' + deptcode + '</dept><name>' + name + '</name><description>' + desc + '</description><role>' + role + '</role><image><image href="' + image + '"/></image><associatedir><associatedir href="' + asdir + '"/></associatedir></person>'); } file.writeline('</seating_plan>'); file.close(); }

how work when including tbody tag?

==================================================================

update:

html:

<!doctype html> <html> <head> <meta charset="utf-8"> <title></title> <script type="text/javascript" src="admin_javascript.js"></script> </head> <body> <div id="header_logo" ></div> <div id="header_logo2">bmw uk</div> <div id="admin_header">bmw layout editor</div> <div id="admin_nav"> <a id="btn_xml" class="admin_nav_buttons">xml</a> <a class="admin_nav_buttons">layout</a> </div> <div id="admin_xml"> <div id="xml_buttons2">load</div> <div id="xml_buttons" onclick="writexml()">save</div> <span>&nbsp;</span> <p class="admin_headers">departments</p> <div id="admin_dept_container"></div> <p class="admin_headers">associates</p> <div id="admin_associate_container"> <table id="table_assoc"> <tbody id="tbody_id" > <tr><td><input value="id"></td></tr> <tr><td><input value="deptcode"></td></tr> <tr><td><input value="name"></td></tr> <tr><td><input value="role"></td></tr> </tbody> </table> </div> </div> </body> </html>

there collection of tbodies, can 1 index:

var id = table.tbodies[0].rows[i].cells[0].children[0].value;

javascript jquery html table

No comments:

Post a Comment