arcane quotes problem again

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • DL

    arcane quotes problem again

    The following line is dynamically generated, which works fine at least
    with IE7 but what I want more out of it is to disable this button upon
    click, so, pls see next line of my attempt to use CSS to disable its
    display, however, nasty quote stumbled me.

    var newStr = '... <div id='+i+'><butto n id="chk"+i name="chk"+i
    onclick="doChec kbox(1,'+i2+',' +nr2+');">Add another checkbox</button></
    div>';
    // as said, the above code works

    var newStr ='... <div id='+i+'><butto n id="chk"+i name="chk"+i
    onclick="docume nt.getElementBy Id('chk'+i).sty le.display=''no ne'';doCheckbox (1,'+i2+','+nr2 +');">Add
    another checkbox</button></div>';
    // failed
    // pls note, the quotes surrounding the word, none, are two single
    quotes respectively, the idea is to escape single quote.

    Do you have a solution?

    Thanks.
  • slebetman

    #2
    Re: arcane quotes problem again

    On May 26, 8:57 am, DL <tatata9...@gma il.comwrote:
    The following line is dynamically generated, which works fine at least
    with IE7 but what I want more out of it is to disable this button upon
    click, so, pls see next line of my attempt to use CSS to disable its
    display, however, nasty quote stumbled me.
    >
    var newStr = '... <div id='+i+'><butto n id="chk"+i name="chk"+i
    onclick="doChec kbox(1,'+i2+',' +nr2+');">Add another checkbox</button></
    div>';
    // as said, the above code works
    >
    var newStr ='... <div id='+i+'><butto n id="chk"+i name="chk"+i
    onclick="docume nt.getElementBy Id('chk'+i).sty le.display=''no ne'';doCheckbox (1,'+i2+','+nr2 +');">Add
    another checkbox</button></div>';
    // failed
    // pls note, the quotes surrounding the word, none, are two single
    quotes respectively, the idea is to escape single quote.
    >
    Do you have a solution?
    You escape by backslash, just like in most other languages: \'

    BTW, the string already breaks at: getElementById( 'chk <---- unescaped
    single quote.

    Comment

    • DL

      #3
      Re: arcane quotes problem again

      On May 25, 9:23 pm, slebetman <slebet...@gmai l.comwrote:
      On May 26, 8:57 am, DL <tatata9...@gma il.comwrote:
      >
      >
      >
      >
      >
      The following line is dynamically generated, which works fine at least
      with IE7 but what I want more out of it is to disable this button upon
      click, so, pls see next line of my attempt to use CSS to disable its
      display, however, nasty quote stumbled me.
      >
      var newStr = '... <div id='+i+'><butto n id="chk"+i name="chk"+i
      onclick="doChec kbox(1,'+i2+',' +nr2+');">Add another checkbox</button></
      div>';
      // as said, the above code works
      >
      var newStr ='... <div id='+i+'><butto n id="chk"+i name="chk"+i
      onclick="docume nt.getElementBy Id('chk'+i).sty le.display=''no ne'';doCheckbox ­(1,'+i2+','+nr 2+');">Add
      another checkbox</button></div>';
      // failed
      // pls note, the quotes surrounding the word, none, are two single
      quotes respectively, the idea is to escape single quote.
      >
      Do you have a solution?
      >
      You escape by backslash, just like in most other languages: \'
      >
      BTW, the string already breaks at: getElementById( 'chk <---- unescaped
      single quote.- Hide quoted text -
      >
      - Show quoted text -
      Thanks and shame on me. Now I need a bit more help with quotes. The
      following code use backslash to escape single quote within a singel
      quoted long string, it generated an error, what's wrong?

      var i = 1;
      var newElement = document.create Element();
      newElement.inne rHTML ='Item\' +i+ \':&nbsp;\<inpu t type="text" name=qCK
      \'+i+\' size="60"\>&nbs p;\<br\&nbsp; <div id=\'+i+\'><but ton
      id="chk"+i name="chk"+i onclick="docume nt.getElementBy Id(\'chk
      \'+i).style.dis play=\'none\';d oCheckbox(1,\'+ i2+\',\'+nr2+\' );">Add
      another checkbox</button></div>';


      Comment

      • Tom de Neef

        #4
        Re: arcane quotes problem again

        "DL" <tatata9999@gma il.com wrote:
        >
        var i = 1;
        var newElement = document.create Element();
        newElement.inne rHTML ='Item\' +i+ \':&nbsp;\<inpu t type="text" name=qCK
        \'+i+\' size="60"\>&nbs p;\<br\&nbsp; <div id=\'+i+\'><but ton
        id="chk"+i name="chk"+i onclick="docume nt.getElementBy Id(\'chk
        \'+i).style.dis play=\'none\';d oCheckbox(1,\'+ i2+\',\'+nr2+\' );">Add
        another checkbox</button></div>';

        Yoa assign a string litteral to innerHTML. Taking away the enclosing quotes
        and the escape characters, the contents of that string are (I insert
        linebreaks and blanks for clarity - they are not part of the string value):
        Item' +i+ ':
        &nbsp;<input type="text" name=qCK'+i+' size="60">
        &nbsp;<br>
        &nbsp;
        <div id='+i+'>
        <button id="chk"+i name="chk"+i
        onclick="docume nt.getElementBy Id('chk'+i).sty le.display='non e';
        doCheckbox(1,'+ i2+','+nr2+');" >
        Add another checkbox
        </button>
        </div>

        The problem is in the very first line: what is "Item'+i+': ..." supposed to
        mean?
        Shouldn't that be "Item+i+':. .." ?
        Take away the escape \ in front of all quotes that should not appear in the
        innerHTML (i.e. leave them only araound chk and none.)
        I think it will then get the value
        Item1:
        &nbsp;<input type="text" name=qCK1 size="60">
        &nbsp;<br>
        &nbsp;
        <div id=1>
        <button id="chk"+i name="chk"+i
        onclick="docume nt.getElementBy Id('chk'+i).sty le.display='non e';
        doCheckbox(1,va lue(i2),value(n r2));">
        Add another checkbox
        </button>
        </div>

        Which is still not what you want (it is not valid HTML).
        I think it would be wiser to split things up:
        var labeli = Item+i;
        var inputName = 'qCK'+i;
        var divID = i.toString();
        var buttonID = 'chk'+i
        .... innerHTML = labeli+'&nbsp;\ <input type="text" name='+inputNam e+'
        size="60"... etc.

        Tom


        Comment

        • DL

          #5
          Re: arcane quotes problem again

          On May 26, 5:42 am, "Tom de Neef" <tden...@qolor. nlwrote:
          "DL" <tatata9...@gma il.com wrote:
          >
          var i = 1;
          var newElement = document.create Element();
          newElement.inne rHTML ='Item\' +i+ \':&nbsp;\<inpu t type="text" name=qCK
          >
          \'+i+\' size="60"\>&nbs p;\<br\&nbsp; <div id=\'+i+\'><but ton
          id="chk"+i name="chk"+i  onclick="docume nt.getElementBy Id(\'chk
          \'+i).style.dis play=\'none\';d oCheckbox(1,\'+ i2+\',\'+nr2+\' );">Add
          another checkbox</button></div>';
          >
          Yoa assign a string litteral to innerHTML. Taking away the enclosing quotes
          and the escape characters, the contents of that string are (I insert
          linebreaks and blanks for clarity - they are not part of the string value):
          Item' +i+ ':
          &nbsp;<input type="text" name=qCK'+i+' size="60">
          &nbsp;<br>
          &nbsp;
          <div id='+i+'>
            <button id="chk"+i name="chk"+i
                 onclick="docume nt.getElementBy Id('chk'+i).sty le.display='non e';
          doCheckbox(1,'+ i2+','+nr2+');" >
               Add another checkbox
            </button>
          </div>
          >
          The problem is in the very first line: what is "Item'+i+': ..." supposed to
          mean?
          Shouldn't that be "Item+i+':. .." ?
          Take away the escape \ in front of all quotes that should not appear in the
          innerHTML (i.e. leave them only araound chk and none.)
          I think it will then get the value
          Item1:
          &nbsp;<input type="text" name=qCK1 size="60">
          &nbsp;<br>
          &nbsp;
          <div id=1>
            <button id="chk"+i name="chk"+i
                 onclick="docume nt.getElementBy Id('chk'+i).sty le.display='non e';
          doCheckbox(1,va lue(i2),value(n r2));">
               Add another checkbox
            </button>
          </div>
          >
          Which is still not what you want (it is not valid HTML).
          I think it would be wiser to split things up:
          var labeli = Item+i;
          var inputName = 'qCK'+i;
          var divID = i.toString();
          var buttonID = 'chk'+i
          ... innerHTML = labeli+'&nbsp;\ <input type="text" name='+inputNam e+'
          size="60"... etc.
          >
          Tom
          Thank you very much, Tom. I like your solution and approach, getting
          very close...

          var labeli = 'Checkbox item'+i;
          var inputName = 'qCK'+i;
          var divID = i.toString();
          var buttonID = 'chk'+i

          // alert(labeli+'& nbsp;\<input type="text" name='+inputNam e+'
          size="60"\>&nbs p;\<br/>&nbsp;');
          // ok

          //alert('<div id='+divID+'><b utton id='+buttonID+' name='+buttonID +'
          onclick="doChec kbox(1,'+i2+',' +nr2+');">Add another checkbox</button></
          div>');
          // ok

          // now put them together
          // alert(labeli+'& nbsp;\<input type="text" name='+inputNam e+'
          size="60"\>&nbs p;\<br/>&nbsp;<div id='+divID+'><b utton id='+buttonID+'
          name='+buttonID +' onclick="doChec kbox(1,'+i2+',' +nr2+');">Add another
          checkbox</button></div>');
          // ok

          // final test
          // alert(labeli+'& nbsp;\<input type="text" name='+inputNam e+'
          size="60"\>&nbs p;\<br/>&nbsp;<div id='+divID+'><b utton id='+buttonID+'
          name='+buttonID +' onclick="docume nt.getElementBy Id('+buttonID
          +').style.displ ay=\'none\';doC heckbox(1,'+i2+ ','+nr2+');">Ad d another
          checkbox</button></div>');
          // looks good
          /* but the result of
          document.getEle mentById('+butt onID+').style.d isplay=\'none\' ;
          is
          document.getEle mentById(chk1). style.display=' none';

          Shouldn't it be
          document.getEle mentById('chk1' ).style.display ='none';
          I fumbled around a bit, couldn't get that output.
          */

          newElement.inne rHTML = labeli+'&nbsp;\ <input type="text"
          name='+inputNam e+' size="60"\>&nbs p;\<br/>&nbsp;<div id='+divID
          +'><button id='+buttonID+' name='+buttonID +'
          onclick="docume nt.getElementBy Id('+buttonID+' ).style.display =\'none
          \';doCheckbox(1 ,'+i2+','+nr2+' );">Add another checkbox</button></
          div>';

          Comment

          • Tom de Neef

            #6
            Re: arcane quotes problem again

            /* but the result of
            document.getEle mentById('+butt onID+').style.d isplay=\'none\' ;
            is
            document.getEle mentById(chk1). style.display=' none';
            Shouldn't it be
            document.getEle mentById('chk1' ).style.display ='none';
            You're right.
            You still have the double quotation marks to play with:
            .... document.getEle mentById("'+but tonID+'").style .display=\'none \';

            Tom


            Comment

            • DL

              #7
              Re: arcane quotes problem again

              On May 27, 5:35 am, "Tom de Neef" <tden...@qolor. nlwrote:
              /* but the result of
              document.getEle mentById('+butt onID+').style.d isplay=\'none\' ;
              is
              document.getEle mentById(chk1). style.display=' none';
              Shouldn't it be
              document.getEle mentById('chk1' ).style.display ='none';
              >
              You're right.
              You still have the double quotation marks to play with:
              ...  document.getEle mentById("'+but tonID+'").style .display=\'none \';
              >
              Tom
              Thank you so much, it looks like javascripting does not like me :(
              I tried both using
              document.getEle mentById("'+but tonID+'").style .display=\'none \';
              inline as well as setting it to a var to no avail.

              How come?

              Comment

              • slebetman

                #8
                Re: arcane quotes problem again

                On May 27, 8:09 pm, DL <tatata9...@gma il.comwrote:
                On May 27, 5:35 am, "Tom de Neef" <tden...@qolor. nlwrote:
                >
                /* but the result of
                document.getEle mentById('+butt onID+').style.d isplay=\'none\' ;
                is
                document.getEle mentById(chk1). style.display=' none';
                Shouldn't it be
                document.getEle mentById('chk1' ).style.display ='none';
                >
                You're right.
                You still have the double quotation marks to play with:
                ... document.getEle mentById("'+but tonID+'").style .display=\'none \';
                >
                Tom
                >
                Thank you so much, it looks like javascripting does not like me :(
                I tried both using
                document.getEle mentById("'+but tonID+'").style .display=\'none \';
                inline as well as setting it to a var to no avail.
                >
                How come?
                Ahh.. we're well into quoting hell here and you'll have the same
                problem regardless what language you choose. This is one of the
                reasons why inline HTML is often discouraged - quoting can get very
                confusing very quickly. Instead do something like:

                var i = 1;
                var newElement = document.create Element();
                newElement.inne rHTML ='Item' + i + ':&nbsp;';
                var newInput = document.create Element('input' );
                newInput.type = 'text';
                newInput.name = 'qOK' + i;
                newInput.size = 60;
                newElement.appe ndChild(newInpu t);
                newElement.appe ndChild(documen t.createElement ('br'));
                var newDiv = document.create Element('div');
                newDiv.id = i;
                newElement.appe ndChild(newDiv) ;
                var newButton = document.create Element('button ');
                newButton.id = 'chk' + i;
                newButton.name = 'chk' + i;
                newButton.oncli ck = function () {
                document.getEle mentById('chk' + i).style.displa y = 'none';
                doCheckbox(1,'i 2', 'nr2');
                }
                newButton.inner HTML = 'Add another checkbox';
                newDiv.appendCh ild(newButton);

                of course you can use Thomas's appendFromJSON function to make this
                much easier to type. See:

                Comment

                • DL

                  #9
                  Re: arcane quotes problem again

                  >
                  Thank you so much, it looks like javascripting does not like me :(
                  I tried both using
                  document.getEle mentById("'+but tonID+'").style .display=\'none \';
                  inline as well as setting it to a var to no avail.
                  >
                  How come?
                  >
                  Ahh.. we're well into quoting hell here and you'll have the same
                  problem regardless what language you choose. This is one of the
                  reasons why inline HTML is often discouraged - quoting can get very
                  confusing very quickly. Instead do something like:
                  >
                  var i = 1;
                  var newElement = document.create Element();
                  newElement.inne rHTML ='Item' + i + ':&nbsp;';
                  var newInput = document.create Element('input' );
                  newInput.type = 'text';
                  newInput.name = 'qOK' + i;
                  newInput.size = 60;
                  newElement.appe ndChild(newInpu t);
                  newElement.appe ndChild(documen t.createElement ('br'));
                  var newDiv = document.create Element('div');
                  newDiv.id = i;
                  newElement.appe ndChild(newDiv) ;
                  var newButton = document.create Element('button ');
                  newButton.id = 'chk' + i;
                  newButton.name = 'chk' + i;
                  newButton.oncli ck = function () {
                    document.getEle mentById('chk' + i).style.displa y = 'none';
                    doCheckbox(1,'i 2', 'nr2');}
                  >
                  newButton.inner HTML = 'Add another checkbox';
                  newDiv.appendCh ild(newButton);
                  >
                  of course you can use Thomas's appendFromJSON function to make this
                  much easier to type. See:http://groups.google.com/group/comp....frm/thread...- Hide quoted text -
                  >
                  - Show quoted text -
                  Tom, I'm out of the hell now, at least for now :) you taught me how
                  to escape the single quote, however, I did not fully utilize it in
                  this situation and when I revisited it again just now I resolved it
                  (man, I hate javascripting, so messay. But I expect there would be
                  more advanced javascript headaches ahead...

                  Comment

                  Working...