Jump to content

replaceAll in table


nero987

Recommended Posts

Hi @ll,I'm trying to change all comma's in a table with point so I can load the table in excel without any problems.I want to create a short script to replace all comma's to points, but it isn't working.I'm pretty new to scripting and trying to help myself (especially via W3schools) so my question may be a bit "simple/stupid" At first i've tried this code:

var Table = document.getElementById('members');Table.replaceAll(",", ".");

But it doesn't work this way. Probably because the complete table is not a string? Currently I have this code:

var Table = document.getElementById('members');var rowLength = Table.rows.length;for (i = 1; i < rowLength; i++) {var Cells = Table.rows.item(i).cells;var cellLength = Cells.length;for (var j = 0; j < cellLenght; j++) {  var cellVal = Cells.item(j).innerHTML;  cellVal.replaceAll(",", ".");}}

Also this isn't working. I'm getting the error: Cannot convert 'Table' to object at line 2.I'm pretty sure the ID 'members' is the right ID.The table that needs to change is located here. What am I doing wrong?Should the first scipt also work?Thnx in advance!

Edited by nero987
Link to comment
Share on other sites

"Table" might be a reserved word, at least this forum seems to think it is. The same with "Cells". The first code doesn't work, an HTML element does not have a method called "replaceAll". In fact, nothing in Javascript has a "replaceAll" method. I would use split and join: new_string = old_string.split(",").join("."); The second code would work better, but you're not doing anything with the string after you replace it. You need to write the replaced string back to the cell.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...