1

I'm using JavaScript and HTA to read data in access database (.mdb) on local but having a small issue. My JavaScript code is like this:

function miseryBusiness() {
    var box = document.getElementById("lyrics");
    box.innerHTML = "";

    var db = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='paramore.mdb'";
    var adoConn = new ActiveXObject("ADODB.Connection");
    var adoRS = new ActiveXObject("ADODB.Recordset");
    adoConn.Open(db);
    adoRS.Open("SELECT * from 2007_RIOT WHERE track=4", adoConn, 1, 3);

    var lyrics = adoRS.Fields("lyrics").value;
    box.innerText = lyrics;

    adoRS.Close();
    adoConn.Close();
}

I have a div in the page with id="lyrics". Function gets the specified cell's value and change's div's inner text to that value.

What I want to do is use innerHTML instead of innerText. And if I use inner HTML I get the cell's value as a single line. I want to add line breaks to the end of the each line. Also an anchor to the beginning of the text.

If I was getting the text from a .txt file I'd use

while(!lyrics.AtEndOfStream) {
    box.innerHTML += '<a id="miseryBusiness">' + lyrics.ReadLine() + '<br/>';
}

but this doesn't work with access database. Or I couldn't get it to work. Any ideas?

The HTA and .mdb file I'm using: link1 link2

1 Answer 1

1

If the lyrics are in a Memo field with hard line-breaks then the line terminator is almost certainly <cr><lf>, so try the following:

box.innerHTML = '<a id="miseryBusiness">' + lyrics.replace(/\r\n/g, '<br/>');
2
  • @akinuri Sorry, I guess I misunderstood your issue. Is it that you can retrieve the text from the .mdb file but the formatting is not to your liking? May 7, 2013 at 16:31
  • Exactly. I can get the text and change div's content with innerText but I want to use innerHTML to add an anchor and line breaks to the text.
    – akinuri
    May 7, 2013 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.