When a server sends a string to the Firefox Browser, it is in the following format:
"KEY:a1 VAL:123.45"
This string can consist of multiple records like this.
Below is the code I wrote to handle this information:
var e;
var reply = request.responseText;
var txt = "", tab, key = "", val = "";
var x = reply.getElementsByTagName("KEY:");
for(i = 0; i < x.length; i++)
{
txt = x[i].childNodes[0].nodeValue; // "KEY:%c%c VAL:%.2F"
tab = txt.split(":");
key = "table_" + tab[1].substring(0,1);
val = tab[2];
e = document.getElementById(key);
e.innerHTML = val;
e.style.display = "block";
}
The val
variable currently displays "KEY:a1 VAL:123.45"
instead of just "123.45"
as expected. Additionally, the key
variable doesn't match a table cell correctly, only selecting the first one available.
I am struggling with displaying the values of key
and val
, as using functions like document.write() or alert() don't seem to work for me in Firefox. I'm finding it challenging to trace this code.
If you have any ideas, tips, corrections, or examples of code to share, I would appreciate it. However, please refrain from suggesting libraries, as I aim to achieve this with minimal code.
UPDATE: After reading the comments, I realize there are two approaches to tackle this issue: either by utilizing DOM objects and HTML tags or working with 'strings'. My preference is to stick to the current format, so any guidance towards a 'string' solution would be helpful. Thank you!