Option group help for a beginner?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • What-a-Tool

    Option group help for a beginner?

    I have a school project (ASP) in which I have to call three different ASP
    pages from three different and identical (except for the form "action",
    obviously) HTM pages. This I have no problem with.
    However, as a personal learning project and challenge, I decided to see if I
    could code my initial HTM page to call any of the three ASP pages, depending
    on the condition of an option group. (3 buttons - id="function", id="sub",
    id="class")
    I was hoping it would be as simple as putting a function name in my form
    "action" statement. In the function I thought I would use a switch statement
    to determine the action from the condition of the option group.
    After playing around with this for a couple hours last night, I decided I
    had failed miserably, and it was time to look for some knowledgeble advice.

    Can someone help? Or direct me to a sample somewhere?

    Thank You
    --

    / Sean the Mc /


    "I have not failed. I've just found 10,000 ways that won't work."
    - Thomas Alva Edison (1847-1931)


  • kaeli

    #2
    Re: Option group help for a beginner?

    In article <RWfyc.5365$qg. 4323@lakeread06 >, Die!FrigginSpam mersDieDie!
    @IHateSpam.Net enlightened us with...[color=blue]
    > However, as a personal learning project and challenge, I decided to see if I
    > could code my initial HTM page to call any of the three ASP pages, depending
    > on the condition of an option group. (3 buttons - id="function", id="sub",
    > id="class")
    > I was hoping it would be as simple as putting a function name in my form
    > "action" statement. In the function I thought I would use a switch statement
    > to determine the action from the condition of the option group.
    > After playing around with this for a couple hours last night, I decided I
    > had failed miserably, and it was time to look for some knowledgeble advice.
    >
    > Can someone help? Or direct me to a sample somewhere?[/color]

    The action for the form should be the URL of a default "no javascript"
    page. i.e. action="noscrip t.html". Or it can be a default page -
    whatever you want to have happen if the user has no script or has it
    disabled.
    The onSubmit of the form should call the function, assuming your button
    is a submit button. i.e. type="submit" and onSubmit="retur n myFunction
    ()".
    The function can then look at the option group and change the
    location.href property accordingly. It should then return false so the
    form doesn't actually submit (the location change should fire before
    that, but better safe than sorry).

    Oh, and it's always a good idea not to name things the same name as
    other things. Don't name elements "function" or "id" or "class" or
    "name" and so on. Most of the time it isn't an issue, but it can be, so
    getting in the habit of just not doing it can save you a headache later.
    Same goes for naming things with numbers at the beginning, like
    name="2btn" or some such. It isn't technically illegal, but it can cause
    hassles sometimes.

    --
    --
    ~kaeli~
    Murphy's Law #2030: If at first you don't succeed, destroy
    all evidence that you tried.



    Comment

    • Richard Cornford

      #3
      Re: Option group help for a beginner?

      What-a-Tool wrote:
      <snip>[color=blue]
      > However, as a personal learning project and challenge, I decided to
      > see if I could code my initial HTM page to call any of the three ASP
      > pages,[/color]

      As a learning exercise fair enough, as a design decision with potential
      real world applications exercise extreme caution as without this HTML
      forms and server-side ASP are 100% reliable (or at least as close as
      possible) but with this the whole system becomes dependent on
      client-side squirting, which is a long way from 100% reliable or
      universally available on clients.
      [color=blue]
      > depending on the condition of an option group. (3 buttons -
      > id="function", id="sub", id="class")[/color]

      Do you mean <input type="radio"> buttons? Calling them options is likely
      to be misleading to anyone who understands HTML because they are likely
      to think of OPTION elements (which are not buttons).
      [color=blue]
      > I was hoping it would be as simple as putting a function
      > name in my form "action" statement.[/color]

      The action attribute of a form is specifies as containing a URL so it is
      of no value in executing scripts (except on a very few browsers where
      its use with the javascript: protocol is a seriously misguided dubious
      hack, and always unnecessary).
      [color=blue]
      > In the function I thought I would use a
      > switch statement to determine the action from the condition of the
      > option group.
      > After playing around with this for a couple hours last night, I
      > decided I had failed miserably, and it was time to look for some
      > knowledgeble advice.[/color]

      Read section 2.3 of the newsgroup FAQ and the pages it links to.

      <URL: http://www.jibbering.com/faq/#FAQ2_3 >

      The best place to trigger a function that intends to set the - action -
      property of a form is from the onsubmit handler, as the onsubmit handler
      is called when the form is submitted, but prior to the actual submit (so
      it may be cancelled, for example, as a result of failed client-side
      validation). If code in the onsubmit handler, or a function called from
      there, sets the form's - action - property then the URL assigned will be
      used when the form is submitted.

      Richard.


      Comment

      • bruce

        #4
        Re: Option group help for a beginner?

        "What-a-Tool" <Die!FrigginSpa mmersDieDie!@IH ateSpam.Net> wrote in message news:<RWfyc.536 5$qg.4323@laker ead06>...[color=blue]
        > I have a school project (ASP) in which I have to call three different ASP
        > pages from three different and identical (except for the form "action",
        > obviously) HTM pages. This I have no problem with.
        > However, as a personal learning project and challenge, I decided to see if I
        > could code my initial HTM page to call any of the three ASP pages, depending
        > on the condition of an option group. (3 buttons - id="function", id="sub",
        > id="class")
        > I was hoping it would be as simple as putting a function name in my form
        > "action" statement. In the function I thought I would use a switch statement
        > to determine the action from the condition of the option group.
        > After playing around with this for a couple hours last night, I decided I
        > had failed miserably, and it was time to look for some knowledgeble advice.
        >
        > Can someone help? Or direct me to a sample somewhere?
        >
        > Thank You[/color]


        In the <form> tag, for "action", put
        action="Javascr ipt:DoProcess() "
        Then you can query your option buttons in DoProcess(), do a
        form.submit(), do whatever you want there.

        Better yet, I've found that instead of having a submit button, it's
        better to just use a plain button, which executes a function which
        does form.action,for m.method, does editting, and finally a
        form.submit.

        Comment

        • kaeli

          #5
          Re: Option group help for a beginner?

          In article <d3654513.04061 10800.4c24025d@ posting.google. com>,
          bruce_brodinsky @glic.com enlightened us with...[color=blue]
          >
          > Better yet, I've found that instead of having a submit button, it's
          > better to just use a plain button, which executes a function which
          > does form.action,for m.method, does editting, and finally a
          > form.submit.
          >[/color]

          Except for internet sites that need to work for users who don't have
          javascript. Which all commercial web sites should be able to handle.
          My intranet application, however, does this very thing so that users
          HAVE to enable script to use it.

          --
          --
          ~kaeli~
          Have you forgotten about Jesus?
          Isn't it about time you did?



          Comment

          • What-a-Tool

            #6
            Re: Option group help for a beginner?

            Thanks for your help - I got it working.

            In my function to determine radio button choice I used frmMyForm.actio n =
            "mypage.asp "

            location.href wasn't sending my data entries to the ASP page, whether by my
            lack of know how or otherwise. frmMyForm.actio n = "" did though.

            Once again, thanks

            --

            / Sean the Mc /


            "I have not failed. I've just found 10,000 ways that won't work."
            - Thomas Alva Edison (1847-1931)

            "What-a-Tool" <Die!FrigginSpa mmersDieDie!@IH ateSpam.Net> wrote in message
            news:RWfyc.5365 $qg.4323@lakere ad06...[color=blue]
            > I have a school project (ASP) in which I have to call three different ASP
            > pages from three different and identical (except for the form "action",
            > obviously) HTM pages. This I have no problem with.
            > However, as a personal learning project and challenge, I decided to see if[/color]
            I[color=blue]
            > could code my initial HTM page to call any of the three ASP pages,[/color]
            depending[color=blue]
            > on the condition of an option group. (3 buttons - id="function", id="sub",
            > id="class")
            > I was hoping it would be as simple as putting a function name in my form
            > "action" statement. In the function I thought I would use a switch[/color]
            statement[color=blue]
            > to determine the action from the condition of the option group.
            > After playing around with this for a couple hours last night, I decided I
            > had failed miserably, and it was time to look for some knowledgeble[/color]
            advice.[color=blue]
            >
            > Can someone help? Or direct me to a sample somewhere?
            >
            > Thank You
            > --
            >
            > / Sean the Mc /
            >
            >
            > "I have not failed. I've just found 10,000 ways that won't work."
            > - Thomas Alva Edison (1847-1931)
            >
            >[/color]


            Comment

            • What-a-Tool

              #7
              Re: Option group help for a beginner?

              Have just discovered that using this method doesn't work in Netscape(7.1)
              for some reason. (setting my form action with < frmMyForm.actio n =
              "myasp_page.asp " > ) This works fine in IE.

              Using the location.href to set my page brings me to the proper page, but
              doesn't send my form data to the server. (at least not so my asp page can
              read it)

              Is there another way to do this so it will at least work in Netscape as well
              as IE?

              --

              / Sean the Mc /


              "I have not failed. I've just found 10,000 ways that won't work."
              - Thomas Alva Edison (1847-1931)

              "What-a-Tool" <Die!FrigginSpa mmersDieDie!@IH ateSpam.Net> wrote in message
              news:Outyc.5588 $qg.3528@lakere ad06...[color=blue]
              > Thanks for your help - I got it working.
              >
              > In my function to determine radio button choice I used frmMyForm.actio n =
              > "mypage.asp "
              >
              > location.href wasn't sending my data entries to the ASP page, whether by[/color]
              my[color=blue]
              > lack of know how or otherwise. frmMyForm.actio n = "" did though.
              >
              > Once again, thanks
              >
              > --
              >
              > / Sean the Mc /
              >
              >
              > "I have not failed. I've just found 10,000 ways that won't work."
              > - Thomas Alva Edison (1847-1931)
              >
              > "What-a-Tool" <Die!FrigginSpa mmersDieDie!@IH ateSpam.Net> wrote in message
              > news:RWfyc.5365 $qg.4323@lakere ad06...[color=green]
              > > I have a school project (ASP) in which I have to call three different[/color][/color]
              ASP[color=blue][color=green]
              > > pages from three different and identical (except for the form "action",
              > > obviously) HTM pages. This I have no problem with.
              > > However, as a personal learning project and challenge, I decided to see[/color][/color]
              if[color=blue]
              > I[color=green]
              > > could code my initial HTM page to call any of the three ASP pages,[/color]
              > depending[color=green]
              > > on the condition of an option group. (3 buttons - id="function",[/color][/color]
              id="sub",[color=blue][color=green]
              > > id="class")
              > > I was hoping it would be as simple as putting a function name in my form
              > > "action" statement. In the function I thought I would use a switch[/color]
              > statement[color=green]
              > > to determine the action from the condition of the option group.
              > > After playing around with this for a couple hours last night, I decided[/color][/color]
              I[color=blue][color=green]
              > > had failed miserably, and it was time to look for some knowledgeble[/color]
              > advice.[color=green]
              > >
              > > Can someone help? Or direct me to a sample somewhere?
              > >
              > > Thank You
              > > --
              > >
              > > / Sean the Mc /
              > >
              > >
              > > "I have not failed. I've just found 10,000 ways that won't work."
              > > - Thomas Alva Edison (1847-1931)
              > >
              > >[/color]
              >
              >[/color]


              Comment

              • Richard Cornford

                #8
                Re: Option group help for a beginner?

                What-a-Tool wrote:[color=blue]
                > Have just discovered that ...[/color]
                <snip>

                Did you read section 2.3 of the newsgroup FAQ and the pages it links to?
                If so why have you disregarded what they say?

                <URL: http://www.jibbering.com/faq/#FAQ2_3 >

                Richard.


                Comment

                • What-a-Tool

                  #9
                  Re: Option group help for a beginner?

                  Alright - I give - what is it that I'm doing wrong?
                  Yeah, I read the faq. Sorry - don't see the relevance.

                  Did a search for related posts - didn't find one.

                  If I'm posting in the wrong group, point me in the right direction.

                  If I'm asking a stupid question, sorry - I stated in the subject that I was
                  a beginner.

                  Is it because the question relates to ASP?
                  Sorry - I thought it dealt more with the client side JavaScript I'm trying
                  to code.

                  Please tell, rather than continually pointing at the same overly wordy faq
                  sheet that I don't have time to read every word of.

                  --

                  / Sean the Mc /


                  "I have not failed. I've just found 10,000 ways that won't work."
                  - Thomas Alva Edison (1847-1931)

                  "Richard Cornford" <Richard@litote s.demon.co.uk> wrote in message
                  news:caibd2$hf$ 1$8302bc10@news .demon.co.uk...[color=blue]
                  > What-a-Tool wrote:[color=green]
                  > > Have just discovered that ...[/color]
                  > <snip>
                  >
                  > Did you read section 2.3 of the newsgroup FAQ and the pages it links to?
                  > If so why have you disregarded what they say?
                  >
                  > <URL: http://www.jibbering.com/faq/#FAQ2_3 >
                  >
                  > Richard.
                  >
                  >[/color]


                  Comment

                  • Dr John Stockton

                    #10
                    Re: Option group help for a beginner?

                    JRS: In article <caibd2$hf$1$83 02bc10@news.dem on.co.uk>, seen in
                    news:comp.lang. javascript, Richard Cornford
                    <Richard@litote s.demon.co.uk> posted at Sun, 13 Jun 2004 20:54:08 :[color=blue]
                    >What-a-Tool wrote:[color=green]
                    >> Have just discovered that ...[/color]
                    ><snip>
                    >
                    >Did you read section 2.3 of the newsgroup FAQ and the pages it links to?
                    >If so why have you disregarded what they say?
                    >
                    ><URL: http://www.jibbering.com/faq/#FAQ2_3 >[/color]

                    ISTM that Sec 2.3 does need to have its paragraphs numbered (perhaps
                    with <H4>); and that it might be improved by a total re-write.

                    No doubt you had Paragraph 6 particularly in mind.


                    I was thinking about testing javascript and Web pages; sometimes I fear
                    that novices may edit their sources, upload to the web, and test while
                    on-line, without realising that it can all be tested locally. Clearly
                    there's quite a bit that could be said, and the FAQ should not itself
                    say much; but there should be room for a few links, that could be found
                    by searching for "test" and "valid". Perhaps a page in the Notes?

                    --
                    © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
                    <URL:http://jibbering.com/faq/> JL / RC : FAQ for 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

                    • What-a-Tool

                      #11
                      Re: Option group help for a beginner?

                      "Dr John Stockton" <spam@merlyn.de mon.co.uk> wrote in message
                      news:GCvdshCaeb zAFwTF@merlyn.d emon.co.uk...
                      ..[color=blue]
                      >
                      > No doubt you had Paragraph 6 particularly in mind.
                      >
                      >[/color]

                      AAAHH! - I think I get it - Sorry



                      --

                      / Sean the Mc /


                      "I have not failed. I've just found 10,000 ways that won't work."
                      - Thomas Alva Edison (1847-1931)


                      Comment

                      • Richard Cornford

                        #12
                        Re: Option group help for a beginner?

                        Dr John Stockton wrote:[color=blue]
                        > Richard Cornford wrote:[/color]
                        <snip>[color=blue][color=green]
                        >>Did you read section 2.3 of the newsgroup FAQ and the pages it
                        >>links to? If so why have you disregarded what they say?
                        >>
                        >><URL: http://www.jibbering.com/faq/#FAQ2_3 >[/color]
                        >
                        > ISTM that Sec 2.3 does need to have its paragraphs numbered (perhaps
                        > with <H4>); and that it might be improved by a total re-write.[/color]

                        There are quite a lot of similar suggestions for improvements to the
                        general presentation (in text and HTML versions) but they will take a
                        serious revision of the XML format used as the current version will not
                        accommodate them. I did start looking into revising the XML format to
                        make it more flexible/expressive but I don't want to commit to a new
                        format until I have got it right, else it will become another ongoing
                        task.
                        [color=blue]
                        > No doubt you had Paragraph 6 particularly in mind.[/color]

                        Well I didn't know how the OP would be replying to post when I initially
                        made the suggestion. I was thinking more in terms of the general advice
                        on asking questions, and particularly the suggestions about posting
                        code. Though I didn't want to be that specific in case the other
                        important material was missed along the way.
                        [color=blue]
                        > I was thinking about testing javascript and Web pages; sometimes I
                        > fear that novices may edit their sources, upload to the web, and test
                        > while on-line, without realising that it can all be tested locally.
                        > Clearly there's quite a bit that could be said, and the FAQ should
                        > not itself say much; but there should be room for a few links, that
                        > could be found by searching for "test" and "valid". Perhaps a page
                        > in the Notes?[/color]

                        Testing on a live site isn't a good idea, but uploading to a test area
                        within a site wouldn't be that inconvenient given a broadband
                        connection. But a page on testing wouldn't be a bad idea either.

                        Richard.


                        Comment

                        • What-a-Tool

                          #13
                          Re: Option group help for a beginner?


                          Following is some of my code:

                          <form name="frmsubmit F" id="frmsubmitF " onsubmit="retur n wheretogo();"
                          action="../noscript.htm" method="post">

                          function wheretogo()
                          {

                          if (eval("document .frmsubmitF.cal lfunc.checked") == true)
                          {
                          alert("Calling ASP Function");
                          frmsubmitF.acti on = "converttempfun ction.asp";

                          ----------------------------------------------------------------------------
                          --

                          My Problem has been pointed out to me :

                          Above:
                          frmsubmitF.acti on = "converttempfun ction.asp";

                          Should be:
                          document.frmsub mitF.action = "converttempfun ction.asp";


                          --

                          / Sean the Mc /

                          "I have not failed. I've just found 10,000 ways that won't work."
                          - Thomas Alva Edison (1847-1931)


                          Comment

                          • Richard Cornford

                            #14
                            Re: Option group help for a beginner?

                            What-a-Tool wrote:
                            <snip>[color=blue]
                            > if (eval("document .frmsubmitF.cal lfunc.checked") == true)[/color]

                            As you are learning you might like to know that it is never necessary to
                            compare a boolean value with a boolean value to get a boolean result, as
                            you are doing in this case. The - checked - property of a checkbox/radio
                            button is a boolean property, its value is either true or false. The
                            comparison operator - == - produces a boolean result, true if the
                            (type-converted) values are equal, false otherwise. When you compare a
                            boolean value that may be either true of false with true the result you
                            will get will be true is the value was true and false if the value was
                            false. Making the comparison an extra operation that always returns a
                            value equivalent to the value being tested.

                            The - if - statement examines its expression to see if its
                            (type-converted to boolean) value is true of false, so merely placing a
                            reference to the appropriate - checked - property in the - if -
                            expression will have exactly the same outcome as your comparison
                            operation.

                            Also, the - eval - function is almost never needed in javascript, and so
                            almost never used by javascript authors who know what they are doing. It
                            is often used to resolve dynamically created dot notation property
                            accessors, javascript natively offers bracket notation property
                            accessors for that task so - eval - isn't needed for that task (and is
                            extremely in efficient at the task). But you are not even evaluation a
                            dynamically constructed dot notation property accessor. Your string
                            value for use with - eval - is literal and so:-

                            eval("document. frmsubmitF.call func.checked")

                            - is *exactly* the same, in terms of what it does, as:-

                            document.frmsub mitF.callfunc.c hecked

                            - except that the - eval - call is two to twenty times slower (depending
                            on the browser) and may not function on ECMA 327 "compact profile"
                            implementations (as might be found in small embedded browsers), where -
                            eval - is optional.

                            So your - if - statement can be re-written as:-

                            if(document.frm submitF.callfun c.checked){

                            - and do exactly the same as it does now, but be faster, clearer and
                            more reliable.

                            <snip>[color=blue]
                            > My Problem has been pointed out to me :
                            >
                            > Above:
                            > frmsubmitF.acti on = "converttempfun ction.asp";
                            >
                            > Should be:
                            > document.frmsub mitF.action = "converttempfun ction.asp";[/color]

                            And that is an error that is impossible to guess but easy to *see*.

                            Incidentally, asking people to write you specific explanations because
                            you "don't have time to read every word of" a pre-written explanation
                            that you have been referred to is not going to go down well on Usenet.
                            These web page explanations get written to save us time by not having to
                            re-write the same explanation of the same things over and over again.

                            Richard.



                            Comment

                            • Andrew Thompson

                              #15
                              Re: Option group help for a beginner?

                              On Tue, 15 Jun 2004 01:41:41 +0100, Richard Cornford wrote:
                              ....[color=blue]
                              > Testing on a live site isn't a good idea, but uploading to a test area
                              > within a site wouldn't be that inconvenient given a broadband
                              > connection.[/color]

                              I feel this is a good example of some of the benefits..
                              <http://www.physci.org/test/003url/>

                              (Though I should move paragraph two of
                              'errata' to top of page..)
                              [color=blue]
                              >..But a page on testing wouldn't be a bad idea either.[/color]

                              This page is on preparing an example..
                              <http://www.physci.org/codes/sscce.jsp>
                              ...but it includes some good tips on general
                              testing strategies designed to help the reader
                              help themselves. As a classic example..
                              <http://groups.google.c om/groups?th=db27b 22cfc6fb63f>
                              I never actually saw the complete code,
                              yet the OP solved the problem by following
                              the strategy outlined in the SSCCE document. ;-)

                              I suppose, to quit the rambling, I would be
                              willing to alter an existing example to show
                              what an 'ideal' example might contain, and to
                              massage the SSCCE document so it has more focus
                              on JS.

                              [ Of course, I still need to attend to those
                              things that are crashing Dr. J.S.'s IE 4.. :-O ]

                              --
                              Andrew Thompson
                              http://www.PhySci.org/ Open-source software suite
                              http://www.PhySci.org/codes/ Web & IT Help
                              http://www.1point1C.org/ Science & Technology

                              Comment

                              Working...