javascript manipulating html data in string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ebajumpaa
    New Member
    • Aug 2008
    • 2

    javascript manipulating html data in string

    this is an odd problem that i can't find a solution to.
    snippit:
    "function("'+id +'","' + Times + '","' + TimeData + '","#FFFFFF" ," "," "," ")"

    what happens:

    function( bgColor=#ffffff hash?,?0?,?7:00 :00 ?)? ?,? AM?,?#FFFFFF?,? >


    this seems to reorder my code and replace quotes.

    now all im doing is writing to the innerHTML tag of a div.
    javascript seems to also add the <tbody> tag to any table i create through javascript.

    has anyone ran into this before
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    hi ...

    to the first problem:

    [CODE=javascript]"function("'+id +'","' + Times + '","' + TimeData + '","#FFFFFF" ," "," "," ")"[/CODE]
    should rather look like:

    [CODE=javascript]"function(" + "'" + id + "'" + ...[/CODE]
    but please show how you really use your code ... probably it would be enough just to escape some quotes or replace doubles with single or vice versa ...

    to your second question: yes ... since a table implies to have a tbody javascript's dom-methods work with that. while FF/Mozilla allows you to add rows directly to the table-node IE is more strict in this special case only ;) ... and forces you to append to the tbody ...

    kind regards

    Comment

    • ebajumpaa
      New Member
      • Aug 2008
      • 2

      #3
      found the major issue that was causing the error, seemed some quotes didnt match up correctly, that is now fixed.

      i am still a little confused at the fact , when you hav ethis issue, java script reformats the string to include the bgcolor inside the onclick event. only reason this is odd because i didn't write it this way and it still occurs. is there anything in java script that would cause this.

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5388

        #4
        it is hard to say what the problem really is here without seeing your entire usage ... typically you have to create the following:

        [CODE=javascript]var s = '\"function foo(param) { alert(param) }; foo(\'bar\');\" ';[/CODE]
        and asssign that to a html-node's event-handler. now it is important how you do that ... in either case it should come out as something like this:

        [HTML]<node onclick="functi on foo(param) { alert(param) }; foo('bar');"/>[/HTML]
        note the use of double and single quotes here ... the script must take care of this.

        kind regards

        Comment

        Working...