Function help

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

    Function help

    I am writing this function and I think I messed up something cause it won't
    work. Can someone help me see what I am doing wrong?? I have included the
    function and the part where I call the function. Thanks.

    <script language="JavaS cript">
    function rankme(form) {
    var ans1 = eval(form.q1.va lue);
    var ans2 = eval(form.q2.va lue);
    var ans4 = eval(form.q4.va lue);
    var ans5 = eval(form.q5.va lue);
    var ans7 = eval(form.q7.va lue);
    var ans8 = eval(form.q8.va lue);
    var ans10 = eval(form.q10.v alue);
    var ans11 = eval(form.q11.v alue);

    var result = (ans1 + ans2 + ans4 + ans5 + ans7 + ans8 + ans10 + ans11) / 8;

    if (result < 1.5 {
    window.open("ht tp://cassidygirls.co m/2004/aparent.htm")
    }
    else {
    if (result < 2.5 {
    window.open("ht tp://cassidygirls.co m/2004/adoptee.htm")
    }
    else {
    if (result < 3.5 {
    window.open("ht tp://cassidygirls.co m/2004/bparent.htm")
    }
    else {
    if (result < 4.5 {
    window.open("ht tp://cassidygirls.co m/2004/pap.htm")
    }
    else {
    if (result < 5.5 {
    window.open("ht tp://cassidygirls.co m/2004/fac.htm")
    }
    else {
    if (result < 6.5 {
    window.open("ht tp://cassidygirls.co m/2004/sw.htm")
    }
    }
    }
    }
    }
    }
    }

    </script>

    <input type=button name=score value="Tell me what I am!"
    onClick="javasc ript:rankme(thi s.form)">

    --

    Kari-Lyn Bjorn
    "You don't love someone because they are beautiful, they are beautiful
    because you love them." - Anon.


  • Evertjan.

    #2
    Re: Function help

    KL wrote on 12 dec 2004 in comp.lang.javas cript:[color=blue]
    > <script language="JavaS cript">[/color]

    <script type="text/JavaScript">

    // your way is 5 yeard outdated
    [color=blue]
    > function rankme(form) {
    > var ans1 = eval(form.q1.va lue);[/color]

    var ans1 = 1*form.q1.value ;

    eval is evil, and probably unneccessary, but you don't show the form.

    use the 1* for numerical conversion. However witout propper validating,
    an input of "pfft" will error either the unary + or [see below]

    [color=blue]
    >
    > var result = (ans1 + ans2 + ans4 + ans5 + ans7 + ans8 + ans10 + ans11)
    > / 8;[/color]

    without numerical conversion validation you will get

    for inputs 24,4,6,8,pfft,9 9

    a string like

    26468pfft99, which will not be dividable by 8

    for inputs 24,4,6,8,1111,9 9

    a string like

    26468111199, which will be dividable by 8,
    but will not give the result you want, imho

    [color=blue]
    >
    > if (result < 1.5 {[/color]

    if (result < 1.5 ) { // THIS IS YOUR HARD ERROR forgetting ")"

    [color=blue]
    > window.open("ht tp://cassidygirls.co m/2004/aparent.htm")
    >}
    > else {[/color]

    else
    [color=blue]
    > else {[/color]

    else
    [color=blue]
    > if (result < 6.5 {
    > window.open("ht tp://cassidygirls.co m/2004/sw.htm")
    >}[/color]

    // what if the result >= 6.5 ???

    // do not use the below }}}}}}
    the extra {}'s after the elses are unneccesary

    [color=blue]
    >}
    >}[/color]
    [color=blue]
    > onClick="javasc ript:rankme(thi s.form)">[/color]

    onClick="rankme (this.form);">

    the "javascript :" is superfluous

    =============== =============== ======

    Consequently, but untested:

    <script type="text/JavaScript">

    function validateme(x){
    if (NaN(x)){error= true;return 0};
    return 1*x;
    };


    function rankme(form) {
    var error = false;
    result = validateme(form .q1.value)+
    validateme(form .q2.value)+
    validateme(form .q4.value)+
    validateme(form .q5.value)+
    validateme(form .q7.value)+
    validateme(form .q8.value)+
    validateme(form .q10.value)+
    validateme(form .q11.value);
    if (error) return;
    var result = result / 8;

    if (result < 1.5 ) myfile = "aparent.ht m"
    else if (result < 2.5 ) myfile = "adoptee.ht m"
    else if (result < 3.5 ) myfile = "bparent.ht m"
    else if (result < 4.5 ) myfile = "pap.htm"
    else if (result < 5.5 ) myfile = "fac.htm"
    else if (result < 6.5 ) myfile = "sw.htm"
    else return;

    window.open("ht tp://cassidygirls.co m/2004/"+myfile);
    };

    </script>




    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

    Comment

    • KL

      #3
      Re: Function help

      I made those corrections as you so helpfully provided, but it still isn't
      working. Can you take a look at the page and see if I haven't just honked
      it up completely? I am trying to get this done before I go in for surgery
      tomorrow.



      --

      Kari-Lyn Bjorn
      "You don't love someone because they are beautiful, they are beautiful
      because you love them." - Anon.
      "Evertjan." <exjxw.hannivoo rt@interxnl.net > wrote in message
      news:Xns95BDB07 78E0C1eejj99@19 4.109.133.29...[color=blue]
      > KL wrote on 12 dec 2004 in comp.lang.javas cript:[color=green]
      >> <script language="JavaS cript">[/color]
      >
      > <script type="text/JavaScript">
      >
      > // your way is 5 yeard outdated
      >[color=green]
      >> function rankme(form) {
      >> var ans1 = eval(form.q1.va lue);[/color]
      >
      > var ans1 = 1*form.q1.value ;
      >
      > eval is evil, and probably unneccessary, but you don't show the form.
      >
      > use the 1* for numerical conversion. However witout propper validating,
      > an input of "pfft" will error either the unary + or [see below]
      >
      >[color=green]
      >>
      >> var result = (ans1 + ans2 + ans4 + ans5 + ans7 + ans8 + ans10 + ans11)
      >> / 8;[/color]
      >
      > without numerical conversion validation you will get
      >
      > for inputs 24,4,6,8,pfft,9 9
      >
      > a string like
      >
      > 26468pfft99, which will not be dividable by 8
      >
      > for inputs 24,4,6,8,1111,9 9
      >
      > a string like
      >
      > 26468111199, which will be dividable by 8,
      > but will not give the result you want, imho
      >
      >[color=green]
      >>
      >> if (result < 1.5 {[/color]
      >
      > if (result < 1.5 ) { // THIS IS YOUR HARD ERROR forgetting ")"
      >
      >[color=green]
      >> window.open("ht tp://cassidygirls.co m/2004/aparent.htm")
      >>}
      >> else {[/color]
      >
      > else
      >[color=green]
      >> else {[/color]
      >
      > else
      >[color=green]
      >> if (result < 6.5 {
      >> window.open("ht tp://cassidygirls.co m/2004/sw.htm")
      >>}[/color]
      >
      > // what if the result >= 6.5 ???
      >
      > // do not use the below }}}}}}
      > the extra {}'s after the elses are unneccesary
      >
      >[color=green]
      >>}
      >>}[/color]
      >[color=green]
      >> onClick="javasc ript:rankme(thi s.form)">[/color]
      >
      > onClick="rankme (this.form);">
      >
      > the "javascript :" is superfluous
      >
      > =============== =============== ======
      >
      > Consequently, but untested:
      >
      > <script type="text/JavaScript">
      >
      > function validateme(x){
      > if (NaN(x)){error= true;return 0};
      > return 1*x;
      > };
      >
      >
      > function rankme(form) {
      > var error = false;
      > result = validateme(form .q1.value)+
      > validateme(form .q2.value)+
      > validateme(form .q4.value)+
      > validateme(form .q5.value)+
      > validateme(form .q7.value)+
      > validateme(form .q8.value)+
      > validateme(form .q10.value)+
      > validateme(form .q11.value);
      > if (error) return;
      > var result = result / 8;
      >
      > if (result < 1.5 ) myfile = "aparent.ht m"
      > else if (result < 2.5 ) myfile = "adoptee.ht m"
      > else if (result < 3.5 ) myfile = "bparent.ht m"
      > else if (result < 4.5 ) myfile = "pap.htm"
      > else if (result < 5.5 ) myfile = "fac.htm"
      > else if (result < 6.5 ) myfile = "sw.htm"
      > else return;
      >
      > window.open("ht tp://cassidygirls.co m/2004/"+myfile);
      > };
      >
      > </script>
      >
      >
      >
      >
      > --
      > Evertjan.
      > The Netherlands.
      > (Please change the x'es to dots in my emailaddress)[/color]



      Comment

      • Evertjan.

        #4
        Re: Function help

        KL wrote on 12 dec 2004 in comp.lang.javas cript:
        [color=blue]
        > I made those corrections as you so helpfully provided, but it still
        > isn't working. Can you take a look at the page and see if I haven't
        > just honked it up completely? I am trying to get this done before I
        > go in for surgery tomorrow.
        >
        > http://cassidygirls.com/2004/index.htm
        >[/color]

        type=radio name="q3" value="mel1"

        How would you ever expect to add numerically
        string values like the above?

        "mel1mel2" would error out if you try to devide it by 8.

        =============== ====

        I think you overestimate your ability in attempting such a large page.

        Try to debug a simple page by reading and understanding error messages
        and inserting breakpoints like alert(validatem e(form.q1.value ))

        First try a such simple page and exactly define for yourself what you
        want to achieve. Perhaps later you will be able to more.

        Sorry, programming is not just writing code, but minutely understanding
        the code and the requirements of your page.

        =============== ====
        a
        and lastly, please do not toppost on usenet.

        --
        Evertjan.
        The Netherlands.
        (Please change the x'es to dots in my emailaddress)

        Comment

        • KL

          #5
          Re: Function help

          "Evertjan." <exjxw.hannivoo rt@interxnl.net > wrote in message
          news:Xns95BDB94 973150eejj99@19 4.109.133.29...[color=blue]
          > KL wrote on 12 dec 2004 in comp.lang.javas cript:
          >[color=green]
          >> I made those corrections as you so helpfully provided, but it still
          >> isn't working. Can you take a look at the page and see if I haven't
          >> just honked it up completely? I am trying to get this done before I
          >> go in for surgery tomorrow.
          >>
          >> http://cassidygirls.com/2004/index.htm
          >>[/color]
          >
          > type=radio name="q3" value="mel1"
          >
          > How would you ever expect to add numerically
          > string values like the above?
          >
          > "mel1mel2" would error out if you try to devide it by 8.[/color]

          Yeah, I know that...those particular questions aren't included in the
          figuring, they are trick questions and will link to a different webpage if a
          certain answer is selected, otherwise I really don't use it for anything
          else.[color=blue]
          >
          > =============== ====
          >
          > I think you overestimate your ability in attempting such a large page.
          >
          > Try to debug a simple page by reading and understanding error messages
          > and inserting breakpoints like alert(validatem e(form.q1.value ))
          >
          > First try a such simple page and exactly define for yourself what you
          > want to achieve. Perhaps later you will be able to more.
          >
          > Sorry, programming is not just writing code, but minutely understanding
          > the code and the requirements of your page.
          >
          > =============== ====
          > a
          > and lastly, please do not toppost on usenet.[/color]

          I didn't mean to, really. My newsreader seemed to have a conniption this
          morning. Or maybe it was me not being quite fully awake! Thanks again for
          your help!

          KL
          [color=blue]
          > --
          > Evertjan.
          > The Netherlands.
          > (Please change the x'es to dots in my emailaddress)[/color]



          Comment

          • Michael Winter

            #6
            Re: Function help

            On Sun, 12 Dec 2004 10:44:14 -0600, KL <klbjornme@aohe ll.com> wrote:
            [color=blue]
            > "Evertjan." <exjxw.hannivoo rt@interxnl.net > wrote in message
            > news:Xns95BDB07 78E0C1eejj99@19 4.109.133.29...
            >[color=green]
            >> KL wrote on 12 dec 2004 in comp.lang.javas cript:[/color][/color]

            [snip]
            [color=blue][color=green]
            >> <script type="text/JavaScript">[/color][/color]

            Although it's not really required, convention puts MIME types in all
            lowercase.

            [snip]
            [color=blue][color=green][color=darkred]
            >>> var ans1 = eval(form.q1.va lue);[/color]
            >>
            >> var ans1 = 1*form.q1.value ;[/color][/color]

            Using unary plus, rather than multiplying by one, is preferred.

            [snip]
            [color=blue][color=green]
            >> function validateme(x){
            >> if (NaN(x)){error= true;return 0};[/color][/color]

            This will cause an error. However, the isNaN function generally isn't very
            useful unless you intend to allow *any* form of number.
            [color=blue][color=green]
            >> return 1*x;
            >> };[/color][/color]

            return +x;
            [color=blue][color=green]
            >> function rankme(form) {
            >> var error = false;[/color][/color]

            This won't work. The validateme function creates a global variable, error.
            This local variable will hide it so error will always be false.

            [snip]
            [color=blue][color=green]
            >> if (result < 1.5 ) myfile = "aparent.ht m"[/color][/color]

            I'd recommend that braces are always included.

            [snip]
            [color=blue]
            > I made those corrections as you so helpfully provided, but it still isn't
            > working.[/color]

            The reason is that

            form.q1

            and the like will return a collection of elements that represent all of
            the radio buttons with that name in that form. What you actually need to
            do is search that collection for the selected element and return its value.

            function getCheckedValue (form, group) {
            group = form.elements[group];
            for(var i = 0, n = group.length; i < n; ++i) {
            if(group[i].checked) {return group[i].value;}
            }
            }

            Combining this with rankMe, you'll get:

            /* I've changed the function name just for my tastes.
            * Change it back to rankme if you want to.
            */
            function rankMe(form) {var fileName;
            /* If the questions were sequential, this could become a loop,
            * which would be must simpler:
            *
            * for(var i = 1, n = 8; i <= n; ++i) {
            * result += getCheckedValue (form, 'q' + i);
            * }
            *
            * You could also perform the error correction here, allowing you
            * to easily state what the visitor missed:
            *
            * for(var i = 1, n = 8; i <= n; ++i) {
            * result += getCheckedValue (form, 'q' + i);
            * if(isNaN(result )) {
            * // Error
            * }
            * }
            */
            var result = (getCheckedValu e(form, 'q1')
            + getCheckedValue (form, 'q2') + getCheckedValue (form, 'q4')
            + getCheckedValue (form, 'q5') + getCheckedValue (form, 'q7')
            + getCheckedValue (form, 'q8') + getCheckedValue (form, 'q10')
            + getCheckedValue (form, 'q11')) / 8;

            /* getCheckedValue will return undefined if no values were
            * checked. When this is converted to a number, it becomes NaN
            * (Not a Number). If the expression below is true, the visitor
            * missed an answer.
            */
            if(isNaN(result )) {
            /* If you want to show an error, do it here.
            *
            * For example:
            * alert('Please answer all of the questions before proceeding');
            */
            return;
            }

            if(result < 1.5) {fileName = 'aparent.htm';}
            else if (result < 2.5) {fileName = 'adoptee.htm';}
            else if (result < 3.5) {fileName = 'bparent.htm';}
            else if (result < 4.5) {fileName = 'pap.htm';}
            else if (result < 5.5) {fileName = 'fac.htm';}
            else if (result < 6.5) {fileName = 'sw.htm';}
            else {return;}

            window.open('ht tp://cassidygirls.co m/2004/' + fileName, 'result');
            }

            [snip]
            [color=blue]
            > I am trying to get this done before I go in for surgery tomorrow.[/color]

            I hope it goes well.

            Mike


            Please don't top-post.

            --
            Michael Winter
            Replace ".invalid" with ".uk" to reply by e-mail.

            Comment

            • Mick White

              #7
              Re: Function help

              KL wrote:
              [color=blue]
              > I made those corrections as you so helpfully provided, but it still isn't
              > working. Can you take a look at the page and see if I haven't just honked
              > it up completely? I am trying to get this done before I go in for surgery
              > tomorrow.
              >
              > http://cassidygirls.com/2004/index.htm
              >[/color]

              function validateme(x){
              if (NaN(x)){error= true;return 0};
              return 1*x;
              };

              should be:

              function validateme(x){
              if (isNaN(x)){erro r=true;return 0};
              return 1*x;
              }


              Mick

              Comment

              • KL

                #8
                Re: Function help

                "Michael Winter" <M.Winter@bluey onder.co.invali d> wrote in message
                news:opsiwojpyl x13kvk@atlantis ...[color=blue]
                > On Sun, 12 Dec 2004 10:44:14 -0600, KL <klbjornme@aohe ll.com> wrote:
                >[color=green]
                >> "Evertjan." <exjxw.hannivoo rt@interxnl.net > wrote in message
                >> news:Xns95BDB07 78E0C1eejj99@19 4.109.133.29...
                >>[color=darkred]
                >>> KL wrote on 12 dec 2004 in comp.lang.javas cript:[/color][/color]
                >
                > [snip]
                >[color=green][color=darkred]
                >>> <script type="text/JavaScript">[/color][/color]
                >
                > Although it's not really required, convention puts MIME types in all
                > lowercase.
                >
                > [snip]
                >[color=green][color=darkred]
                >>>> var ans1 = eval(form.q1.va lue);
                >>>
                >>> var ans1 = 1*form.q1.value ;[/color][/color]
                >
                > Using unary plus, rather than multiplying by one, is preferred.
                >
                > [snip]
                >[color=green][color=darkred]
                >>> function validateme(x){
                >>> if (NaN(x)){error= true;return 0};[/color][/color]
                >
                > This will cause an error. However, the isNaN function generally isn't very
                > useful unless you intend to allow *any* form of number.
                >[color=green][color=darkred]
                >>> return 1*x;
                >>> };[/color][/color]
                >
                > return +x;
                >[color=green][color=darkred]
                >>> function rankme(form) {
                >>> var error = false;[/color][/color]
                >
                > This won't work. The validateme function creates a global variable, error.
                > This local variable will hide it so error will always be false.
                >
                > [snip]
                >[color=green][color=darkred]
                >>> if (result < 1.5 ) myfile = "aparent.ht m"[/color][/color]
                >
                > I'd recommend that braces are always included.
                >
                > [snip]
                >[color=green]
                >> I made those corrections as you so helpfully provided, but it still isn't
                >> working.[/color]
                >
                > The reason is that
                >
                > form.q1
                >
                > and the like will return a collection of elements that represent all of
                > the radio buttons with that name in that form. What you actually need to
                > do is search that collection for the selected element and return its
                > value.
                >
                > function getCheckedValue (form, group) {
                > group = form.elements[group];
                > for(var i = 0, n = group.length; i < n; ++i) {
                > if(group[i].checked) {return group[i].value;}
                > }
                > }
                >
                > Combining this with rankMe, you'll get:
                >
                > /* I've changed the function name just for my tastes.
                > * Change it back to rankme if you want to.
                > */
                > function rankMe(form) {var fileName;
                > /* If the questions were sequential, this could become a loop,
                > * which would be must simpler:
                > *
                > * for(var i = 1, n = 8; i <= n; ++i) {
                > * result += getCheckedValue (form, 'q' + i);
                > * }
                > *
                > * You could also perform the error correction here, allowing you
                > * to easily state what the visitor missed:
                > *
                > * for(var i = 1, n = 8; i <= n; ++i) {
                > * result += getCheckedValue (form, 'q' + i);
                > * if(isNaN(result )) {
                > * // Error
                > * }
                > * }
                > */
                > var result = (getCheckedValu e(form, 'q1')
                > + getCheckedValue (form, 'q2') + getCheckedValue (form, 'q4')
                > + getCheckedValue (form, 'q5') + getCheckedValue (form, 'q7')
                > + getCheckedValue (form, 'q8') + getCheckedValue (form, 'q10')
                > + getCheckedValue (form, 'q11')) / 8;
                >
                > /* getCheckedValue will return undefined if no values were
                > * checked. When this is converted to a number, it becomes NaN
                > * (Not a Number). If the expression below is true, the visitor
                > * missed an answer.
                > */
                > if(isNaN(result )) {
                > /* If you want to show an error, do it here.
                > *
                > * For example:
                > * alert('Please answer all of the questions before proceeding');
                > */
                > return;
                > }
                >
                > if(result < 1.5) {fileName = 'aparent.htm';}
                > else if (result < 2.5) {fileName = 'adoptee.htm';}
                > else if (result < 3.5) {fileName = 'bparent.htm';}
                > else if (result < 4.5) {fileName = 'pap.htm';}
                > else if (result < 5.5) {fileName = 'fac.htm';}
                > else if (result < 6.5) {fileName = 'sw.htm';}
                > else {return;}
                >
                > window.open('ht tp://cassidygirls.co m/2004/' + fileName, 'result');
                > }
                >
                > [snip][/color]

                ARGHH! I am still getting an error when I select the first answer for all
                applicable answers and then hit the "submit" button. I have looked and
                looked and can't figure out what it wants. Ever get the feeling that your
                scripts just go buggy to drive you mad? lol

                I don't want to have to give up on this. I really want to know what I am
                doing wrong and how to fix it.
                [color=blue][color=green]
                >> I am trying to get this done before I go in for surgery tomorrow.[/color]
                >
                > I hope it goes well.[/color]

                Me too...this is my second back surgery in a year....blech!

                KL[color=blue]
                >
                > Mike
                >
                >
                > Please don't top-post.
                >
                > --
                > Michael Winter
                > Replace ".invalid" with ".uk" to reply by e-mail.[/color]


                Comment

                • Michael Winter

                  #9
                  Re: Function help

                  On Sun, 12 Dec 2004 12:36:54 -0600, KL <klbjornme@aohe ll.com> wrote:

                  [snip]
                  [color=blue][color=green]
                  >> function rankMe(form) {var fileName;
                  >> /* If the questions were sequential, this could become a loop,
                  >> * which would be must simpler:
                  >> *
                  >> * for(var i = 1, n = 8; i <= n; ++i) {
                  >> * result += getCheckedValue (form, 'q' + i);[/color][/color]

                  result += +getCheckedValu e(form, 'q' + i);
                  [color=blue][color=green]
                  >> * }
                  >> *
                  >> * You could also perform the error correction here, allowing you
                  >> * to easily state what the visitor missed:
                  >> *
                  >> * for(var i = 1, n = 8; i <= n; ++i) {
                  >> * result += getCheckedValue (form, 'q' + i);[/color][/color]

                  result += +getCheckedValu e(form, 'q' + i);
                  [color=blue][color=green]
                  >> * if(isNaN(result )) {
                  >> * // Error
                  >> * }
                  >> * }
                  >> */
                  >> var result = (getCheckedValu e(form, 'q1')
                  >> + getCheckedValue (form, 'q2') + getCheckedValue (form, 'q4')
                  >> + getCheckedValue (form, 'q5') + getCheckedValue (form, 'q7')
                  >> + getCheckedValue (form, 'q8') + getCheckedValue (form, 'q10')
                  >> + getCheckedValue (form, 'q11')) / 8;[/color][/color]

                  var result = (+getCheckedVal ue(form, 'q1')
                  + +getCheckedValu e(form, 'q2') + +getCheckedValu e(form, 'q4')
                  + +getCheckedValu e(form, 'q5') + +getCheckedValu e(form, 'q7')
                  + +getCheckedValu e(form, 'q8') + +getCheckedValu e(form, 'q10')
                  + +getCheckedValu e(form, 'q11')) / 8;

                  [snip]
                  [color=blue]
                  > ARGHH! I am still getting an error when I select the first answer for
                  > all applicable answers and then hit the "submit" button.[/color]

                  Replacing all of your code with what I previously posted didn't produce
                  any errors, but it didn't do anything either. I forgot to coerce the
                  return value from getCheckedValue to number. The corrections above (the
                  last of which is the only important one) should solve it.

                  [snip]

                  Hopefully, that should be it.
                  Mike


                  Please trim quotes.

                  --
                  Michael Winter
                  Replace ".invalid" with ".uk" to reply by e-mail.

                  Comment

                  • Michael Winter

                    #10
                    Re: Function help

                    On Sun, 12 Dec 2004 10:44:14 -0600, KL <klbjornme@aohe ll.com> wrote:

                    [snip]
                    [color=blue]
                    > http://cassidygirls.com/2004/index.htm[/color]

                    Not something you'll want to look at before your operation, but you might
                    want to consider validating your HTML. See <URL:http://validator.w3.or g/>.

                    It's not really important for this page because it's just a bit of fun and
                    doesn't really *do* anything, but you should always try to write valid
                    HTML.

                    Mike

                    --
                    Michael Winter
                    Replace ".invalid" with ".uk" to reply by e-mail.

                    Comment

                    • KL

                      #11
                      Re: Function help

                      "Michael Winter" <M.Winter@bluey onder.co.invali d> wrote in message
                      news:opsiwssvsx x13kvk@atlantis ...[color=blue]
                      > On Sun, 12 Dec 2004 12:36:54 -0600, KL <klbjornme@aohe ll.com> wrote:
                      >[/color]
                      [snip][color=blue][color=green]
                      >> ARGHH! I am still getting an error when I select the first answer for
                      >> all applicable answers and then hit the "submit" button.[/color]
                      >
                      > Replacing all of your code with what I previously posted didn't produce
                      > any errors, but it didn't do anything either. I forgot to coerce the
                      > return value from getCheckedValue to number. The corrections above (the
                      > last of which is the only important one) should solve it.
                      >[/color]
                      Well I am about to throw in the towel. Once I hit my 'submit' button I get
                      an error on like line 8 char 1 object expected. I don't get an error when I
                      first load the document, and I am beside myself trying to figure out what I
                      did wrong. I know it just must be something simple, but I can't see it.

                      KL


                      Comment

                      • Michael Winter

                        #12
                        Re: Function help

                        On Sun, 12 Dec 2004 13:28:20 -0600, KL <klbjornme@aohe ll.com> wrote:

                        [snip]
                        [color=blue]
                        > I know it just must be something simple, but I can't see it.[/color]

                        If you don't show what you've done - by updating the page, for example -
                        it's difficult to say. :P

                        Replace the button with

                        <input type="button" name="score" value="Tell me what I am!"
                        onclick="rankMe (this.form);">

                        and replace the SCRIPT element, in its entirety, with this:

                        <script type="text/javascript">
                        function getCheckedValue (form, group) {
                        group = form.elements[group];
                        for(var i = 0, n = group.length; i < n; ++i) {
                        if(group[i].checked) {return group[i].value;}
                        }
                        }

                        function rankMe(form) {
                        var fileName,
                        result = (+getCheckedVal ue(form, 'q1')
                        + +getCheckedValu e(form, 'q2') + +getCheckedValu e(form, 'q4')
                        + +getCheckedValu e(form, 'q5') + +getCheckedValu e(form, 'q7')
                        + +getCheckedValu e(form, 'q8')
                        + +getCheckedValu e(form, 'q10')
                        + +getCheckedValu e(form, 'q11')) / 8;

                        if(isNaN(result )) {
                        alert('Please answer all of the questions before proceeding');
                        return;
                        }

                        if(result < 1.5) {fileName = 'aparent.htm';}
                        else if (result < 2.5) {fileName = 'adoptee.htm';}
                        else if (result < 3.5) {fileName = 'bparent.htm';}
                        else if (result < 4.5) {fileName = 'pap.htm';}
                        else if (result < 5.5) {fileName = 'fac.htm';}
                        else if (result < 6.5) {fileName = 'sw.htm';}
                        else {return;}

                        window.open('ht tp://cassidygirls.co m/2004/' + fileName, 'result');
                        }
                        </script>

                        and you should have no problems. If you still do, you'll need to let us
                        see the changes you've made somehow.

                        Mike

                        --
                        Michael Winter
                        Replace ".invalid" with ".uk" to reply by e-mail.

                        Comment

                        • KL

                          #13
                          Re: Function help

                          "Michael Winter" <M.Winter@bluey onder.co.invali d> wrote in message
                          news:opsiwu78qr x13kvk@atlantis ...[color=blue]
                          > On Sun, 12 Dec 2004 13:28:20 -0600, KL <klbjornme@aohe ll.com> wrote:
                          >
                          > [snip]
                          >[color=green]
                          >> I know it just must be something simple, but I can't see it.[/color]
                          >
                          > If you don't show what you've done - by updating the page, for example -
                          > it's difficult to say. :P
                          >[/color]
                          I have been updating the page each time I made a change to it. But most
                          importantly you helped spectacularly and it works! At least it did for the
                          first one....now off to check the other ones. Man am I releived. Although
                          I still wonder what I had done wrong in the first place lol

                          KL


                          Comment

                          • Michael Winter

                            #14
                            Re: Function help

                            On Sun, 12 Dec 2004 14:20:40 -0600, KL <klbjornme@aohe ll.com> wrote:

                            [snip]
                            [color=blue]
                            > I have been updating the page each time I made a change to it.[/color]

                            Sorry. I must not have been forcing a reload.
                            [color=blue]
                            > But most importantly you helped spectacularly and it works![/color]

                            I'm glad.

                            [snip]
                            [color=blue]
                            > I still wonder what I had done wrong in the first place lol[/color]

                            Well, if you kept copies of the versions that failed, you could always
                            upload them somewhere where they won't get viewed and post a link to them.

                            I did notice that with the first script suggested by Evertjan, you had
                            changed the return statement in his validateme function from

                            return 1*x;

                            to

                            return 1*x,

                            and that caused the syntax error that occurred when the page loaded. You
                            might have done something similar with the other versions. Problems like
                            that can be difficult to spot (which is why I didn't mention it in my
                            earlier posts :) ).

                            Once again, good luck for tomorrow, and I hope development on the rest of
                            your site goes well.

                            Mike

                            --
                            Michael Winter
                            Replace ".invalid" with ".uk" to reply by e-mail.

                            Comment

                            • Dr John Stockton

                              #15
                              Re: Function help

                              JRS: In article <opsiw1wmjex13k vk@atlantis>, dated Sun, 12 Dec 2004
                              22:21:38, seen in news:comp.lang. javascript, Michael Winter <M.Winter@bl
                              ueyonder.co.inv alid> posted :[color=blue]
                              >
                              >I did notice that with the first script suggested by Evertjan, you had
                              >changed the return statement in his validateme function from
                              >
                              > return 1*x;
                              >
                              >to
                              >
                              > return 1*x,[/color]


                              One reason for not using 1*x is that it looks rather like l*x, which is
                              what I first thought the problem must be on reading the above. Writing
                              +x seems safer.

                              --
                              © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
                              <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
                              <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
                              <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

                              Comment

                              Working...