Ignore something in Javascript

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

    #1

    Ignore something in Javascript

    Hello Everyone,

    I posted this question earlier under creating Multiple choice quiz. Is
    it possible to ignore something using javascript. What I am trying to
    do is creating a multiple answer quiz. I have five choices out of
    which user are supposed to choose 3 best choices. The user should get
    feedback on the choices they make. I have been able to provide the
    feedback for all the choices but my problem is I am also getting the
    feedback on the unchecked answers. Is there any way to tell javascript
    not to check unchecked answers.

    I have used the following code to accomplish this:

    function check(f,key){
    var newhtml="";
    key=key.replace (/^.*0/,"").substr(0,5 );
    for(var i=0;i<key.lengt h;i++) {
    if ((key.charAt(i) <"5")==f.elemen ts[i].checked)
    {
    newhtml+= question.a[i] + "<br>Right.<br> ";
    }
    else if ((key.charAt(i) >"5")==f.elemen ts[i].checked)
    {
    newhtml+= question.a[i] + " <br>Wrong.<br>" ;

    } else {return};
    }
    document.getEle mentById("table t").innerHTM L= newhtml;

    Could anyone help me with what's wrong with this code. Any help would
    be appreciated.

    Thanks
  • Ivo

    #2
    Re: Ignore something in Javascript

    "Vandana Rola" wrote[color=blue]
    > I posted this question earlier under creating Multiple choice quiz. Is
    > it possible to ignore something using javascript. What I am trying to
    > do is creating a multiple answer quiz. I have five choices out of
    > which user are supposed to choose 3 best choices. The user should get
    > feedback on the choices they make. I have been able to provide the
    > feedback for all the choices but my problem is I am also getting the
    > feedback on the unchecked answers. Is there any way to tell javascript
    > not to check unchecked answers.
    >
    > I have used the following code to accomplish this:
    >
    > function check(f,key){
    > var newhtml="";
    > key=key.replace (/^.*0/,"").substr(0,5 );
    > for(var i=0;i<key.lengt h;i++) {
    > if ((key.charAt(i) <"5")==f.elemen ts[i].checked)
    > {
    > newhtml+= question.a[i] + "<br>Right.<br> ";
    > }
    > else if ((key.charAt(i) >"5")==f.elemen ts[i].checked)
    > {
    > newhtml+= question.a[i] + " <br>Wrong.<br>" ;[/color]

    Add two slashes in front the above line, and javascript will ignore it.
    // newhtml+= question.a[i] + " <br>Wrong.<br>" ;

    If this is not what you had in mind, post some more code or preferably an
    url so we can get an idea of what actually happens and what exactly should
    not happen.
    Maybe you mean that if f.elements[i] is not checked, the loop should just
    continue. In that case, put this after the for(var i... line:
    if( ! f.elements[i].checked) continue;

    HTH
    Ivo
    [color=blue]
    > } else {return};
    > }
    > document.getEle mentById("table t").innerHTM L= newhtml;
    >
    > Could anyone help me with what's wrong with this code. Any help would
    > be appreciated.
    >
    > Thanks[/color]


    Comment

    • Lee

      #3
      Re: Ignore something in Javascript

      Vandana Rola said:[color=blue]
      >
      >Hello Everyone,
      >
      >I posted this question earlier under creating Multiple choice quiz. Is
      >it possible to ignore something using javascript. What I am trying to
      >do is creating a multiple answer quiz. I have five choices out of
      >which user are supposed to choose 3 best choices. The user should get
      >feedback on the choices they make. I have been able to provide the
      >feedback for all the choices but my problem is I am also getting the
      >feedback on the unchecked answers. Is there any way to tell javascript
      >not to check unchecked answers.
      >
      >I have used the following code to accomplish this:
      >
      >function check(f,key){
      > var newhtml="";
      > key=key.replace (/^.*0/,"").substr(0,5 );
      > for(var i=0;i<key.lengt h;i++) {
      > if ((key.charAt(i) <"5")==f.elemen ts[i].checked)
      > {
      > newhtml+= question.a[i] + "<br>Right.<br> ";
      > }
      > else if ((key.charAt(i) >"5")==f.elemen ts[i].checked)[/color]

      Change that last line to simply:
      else

      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: Ignore something in Javascript

        Vandana Rola wrote:[color=blue]
        > I posted this question earlier under creating Multiple choice quiz. Is
        > it possible to ignore something using javascript.[/color]

        Is this a question.
        [color=blue]
        > [...] Is there any way to tell javascript not to check unchecked answers.[/color]

        // if checkbox is checked
        if (referenceToChe ckBox.checked)
        {
        ...
        }
        [color=blue]
        > I have used the following code to accomplish this:
        >
        > function check(f,key){
        > var newhtml="";
        > key=key.replace (/^.*0/,"").substr(0,5 );
        > for(var i=0;i<key.lengt h;i++) {
        > if ((key.charAt(i) <"5")==f.elemen ts[i].checked)
        > {
        > newhtml+= question.a[i] + "<br>Right.<br> ";
        > }
        > else if ((key.charAt(i) >"5")==f.elemen ts[i].checked)
        > {
        > newhtml+= question.a[i] + " <br>Wrong.<br>" ;
        >
        > } else {return};
        > }
        > document.getEle mentById("table t").innerHTM L= newhtml;[/color]

        The check() method is AFAIS syntactically correct (yet the indentation and
        spacing -- the Pretty Printing -- has potential for improvement) but I do
        not see a line where the check() method is called and you have not provided
        sufficient information of the data it is operating on. Besides, you are
        mixing DOM Level 1+ (getElementById ()) and proprietary DOM (innerHTML)
        without testing which is error-prone:

        <http://pointedears.de/scripts/test/whatami>


        HTH

        PointedEars

        Comment

        • Randy Webb

          #5
          Re: Ignore something in Javascript

          Thomas 'PointedEars' Lahn wrote:[color=blue]
          > Vandana Rola wrote:
          >[color=green]
          >>I posted this question earlier under creating Multiple choice quiz. Is
          >>it possible to ignore something using javascript.[/color]
          >
          >
          > Is this a question.
          >
          >[color=green]
          >>[...] Is there any way to tell javascript not to check unchecked answers.[/color]
          >
          >
          > // if checkbox is checked
          > if (referenceToChe ckBox.checked)
          > {
          > ...
          > }
          >
          >[color=green]
          >>I have used the following code to accomplish this:
          >>
          >>function check(f,key){
          >> var newhtml="";
          >> key=key.replace (/^.*0/,"").substr(0,5 );
          >> for(var i=0;i<key.lengt h;i++) {
          >> if ((key.charAt(i) <"5")==f.elemen ts[i].checked)
          >> {
          >> newhtml+= question.a[i] + "<br>Right.<br> ";
          >> }
          >> else if ((key.charAt(i) >"5")==f.elemen ts[i].checked)
          >> {
          >> newhtml+= question.a[i] + " <br>Wrong.<br>" ;
          >>
          >> } else {return};
          >> }
          >> document.getEle mentById("table t").innerHTM L= newhtml;[/color]
          >
          >
          > The check() method is AFAIS syntactically correct (yet the indentation and
          > spacing -- the Pretty Printing -- has potential for improvement) but I do
          > not see a line where the check() method is called and you have not provided
          > sufficient information of the data it is operating on. Besides, you are
          > mixing DOM Level 1+ (getElementById ()) and proprietary DOM (innerHTML)
          > without testing which is error-prone:
          >
          > <http://pointedears.de/scripts/test/whatami>[/color]

          Could you *please* explain, in your own warped world of thinking, how
          getElementById and innerHTML have *ANY* thing to do with whats on the
          page you reference? Which is browser detection based on userAgent strings?

          Comment

          • Thomas 'PointedEars' Lahn

            #6
            Re: Ignore something in Javascript

            Randy Webb wrote:
            [color=blue]
            > Thomas 'PointedEars' Lahn wrote:[color=green]
            >> <http://pointedears.de/scripts/test/whatami>[/color]
            >
            > Could you *please* explain, in your own warped world of thinking, how
            > getElementById and innerHTML have *ANY* thing to do with whats on the
            > page you reference? Which is browser detection based on userAgent strings?[/color]

            If you would have read it thoroughly, you would have known that it in fact
            deals with differences in client-side object models and explains why those
            cannot be covered with testing HTTP headers (or properties reflecting them)
            or buzzword objects but only with feature tests prior to access.


            PointedEars

            Comment

            • Randy Webb

              #7
              Re: Ignore something in Javascript

              In a message inscribed eternally in the scrolls of comp.lang.javas cript
              Thomas 'PointedEars' Lahn wrote incesantly about:
              [color=blue]
              > Randy Webb wrote:
              >
              >[color=green]
              >>Thomas 'PointedEars' Lahn wrote:
              >>[color=darkred]
              >>><http://pointedears.de/scripts/test/whatami>[/color]
              >>
              >>Could you *please* explain, in your own warped world of thinking, how
              >>getElementByI d and innerHTML have *ANY* thing to do with whats on the
              >>page you reference? Which is browser detection based on userAgent strings?[/color]
              >
              >
              > If you would have read it thoroughly, you would have known that it in fact
              > deals with differences in client-side object models and explains why those
              > cannot be covered with testing HTTP headers (or properties reflecting them)
              > or buzzword objects but only with feature tests prior to access.[/color]

              That is fine and dandy, but it doesn't answer the question. If the page
              is about Object Detection, then you need to reconsider its layout and
              explanations. It covers, mostly, the userAgent string and its flaws.

              P.S. You still haven't accepted/denied my challenge to you about
              accessing a page with anything but NS6.

              --
              Randy

              Comment

              Working...