Radio Submit Button Problem

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

    #1

    Radio Submit Button Problem

    Hi. I hope someone out there who is more versed with JavaScript than
    I can help me with the following annoying problem. Here's the
    problem.

    I have a form with the following layout:

    Column A Column B Column C
    data 4 radio buttons more data
    .... ... ...
    .... ... ...

    The form does have a submit button that leads to a given CGI script.
    The form also has submit buttons as onClick events inside of the radio
    buttons, that point to a different CGI script. The problem is that I
    need to know which particular radio button triggered the onClick
    event, because when I receive the form data, I only want to process
    the row of data for which an event was triggered. As the script is
    now, I just receive everything from the form, without knowing which
    row to actually process. The one thing I thought about trying was to
    call a function with the onClick event that would receive a given row
    id (1 through up to 279), and the use document.write to create a
    hidden value for just that id. I don't know if this is workable,
    though. Am I on the right track with this idea? Is this doable, or
    should I think about trying a different approach?

    Thanks!!!
  • Steven Daedelus

    #2
    Re: Radio Submit Button Problem

    In article <b386d54b.04052 71900.41e3f35@p osting.google.c om>,
    jrolandumuc@yah oo.com (JR) wrote:
    [color=blue]
    > Hi. I hope someone out there who is more versed with JavaScript than
    > I can help me with the following annoying problem. Here's the
    > problem.
    >
    > I have a form with the following layout:
    >
    > Column A Column B Column C
    > data 4 radio buttons more data
    > ... ... ...
    > ... ... ...
    >
    > The form does have a submit button that leads to a given CGI script.
    > The form also has submit buttons as onClick events inside of the radio
    > buttons, that point to a different CGI script. The problem is that I
    > need to know which particular radio button triggered the onClick
    > event, because when I receive the form data, I only want to process
    > the row of data for which an event was triggered. As the script is
    > now, I just receive everything from the form, without knowing which
    > row to actually process. The one thing I thought about trying was to
    > call a function with the onClick event that would receive a given row
    > id (1 through up to 279), and the use document.write to create a
    > hidden value for just that id. I don't know if this is workable,
    > though. Am I on the right track with this idea? Is this doable, or
    > should I think about trying a different approach?
    >
    > Thanks!!![/color]

    Don't think you can do document.write after the page has rendered.

    Here's what I'd do:

    Put in a hidden input field. Create a function to handle the onClick
    event. Pass the id of the radio button to the function. The function
    then sets the value of the hidden field to whatever the id is.

    Make sense?

    Comment

    • Jack Black

      #3
      Re: Radio Submit Button Problem

      Thanks for the reply. I'll give this idea a try. It sounds like a
      workable solution. If it does work, I'll post the code in my next
      reply-someone else out there may have the same problem.

      Thanks again.


      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      • bruce

        #4
        Re: Radio Submit Button Problem

        jrolandumuc@yah oo.com (JR) wrote in message news:<b386d54b. 0405271900.41e3 f35@posting.goo gle.com>...[color=blue]
        > Hi. I hope someone out there who is more versed with JavaScript than
        > I can help me with the following annoying problem. Here's the
        > problem.
        >
        > I have a form with the following layout:
        >
        > Column A Column B Column C
        > data 4 radio buttons more data
        > ... ... ...
        > ... ... ...
        >
        > The form does have a submit button that leads to a given CGI script.
        > The form also has submit buttons as onClick events inside of the radio
        > buttons, that point to a different CGI script. The problem is that I
        > need to know which particular radio button triggered the onClick
        > event, because when I receive the form data, I only want to process
        > the row of data for which an event was triggered. As the script is
        > now, I just receive everything from the form, without knowing which
        > row to actually process. The one thing I thought about trying was to
        > call a function with the onClick event that would receive a given row
        > id (1 through up to 279), and the use document.write to create a
        > hidden value for just that id. I don't know if this is workable,
        > though. Am I on the right track with this idea? Is this doable, or
        > should I think about trying a different approach?
        >
        > Thanks!!![/color]



        From what I see, the only way is to have a loop, and check each
        radio button for the "checked" property. If you give the radio buttons
        the same name, they form an array, so you can use a for-loop.

        Comment

        • Thomas 'PointedEars' Lahn

          #5
          Re: Radio Submit Button Problem

          JR wrote:
          [color=blue]
          > The form does have a submit button that leads to a given CGI script.
          > The form also has submit buttons as onClick events inside of the radio
          > buttons, that point to a different CGI script.[/color]

          What about users without support for client-side scripting?
          [color=blue]
          > The problem is that I need to know which particular radio button
          > triggered the onClick event, because when I receive the form data,
          > I only want to process the row of data for which an event was triggered.[/color]

          Use several submit buttons with the different name and/or different values.
          <input type="image"> may be useful as well, that displays a graphical
          submit button, if supported (since HTML 4 IIRC). Then test against the name
          or the value of the submit button server-side.

          Or use several form elements with different "action" attribute values.

          Anything else is considered harmful.


          PointedEars

          Comment

          • Kien

            #6
            Re: Radio Submit Button Problem

            Hi,
            I would collect the data input by user, stick them into another form
            and submit that form according to the thing that was clicked.

            <form name=F1>
            <input type=radio name=Rad1
            onclick=Chk(thi s.form,this.nam e,this.value)>
            <input type=button value="OK"
            onclick=Chk(thi s.form,"button" ,"button")>
            </form>
            .....
            <form name=F2 action=Onecgi.c gi>
            <input type=hidden name=Val1>
            <input type=hidden name=Val2>
            </form>
            <form name=F3 action=Twocgi.c gi>
            <input type=hidden name=Val1>
            <input type=hidden name=Val2>
            </form>


            <script>

            function Chk(F,Nm,Val){

            if(Nm=="button" { // submit button - fill F2 then submit it
            to Onecgi
            document.F2.Val 1.value=whateve r
            document.F2.Val 2.value=whateve r
            document.F2.sub mit()
            }

            else{ //radio button - fill F3 then submit it to
            Twocgi
            document.F3.Val 1.value=Nm
            document.F3.Val 2.value=Val
            document.F3.sub mit()
            }

            }


            </script>

            Maybe crude and very redundant but it's 7AM and my brain is not
            working ...

            HTH

            Kien

            jrolandumuc@yah oo.com (JR) wrote in message news:<b386d54b. 0405271900.41e3 f35@posting.goo gle.com>...[color=blue]
            > Hi. I hope someone out there who is more versed with JavaScript than
            > I can help me with the following annoying problem. Here's the
            > problem.
            >
            > I have a form with the following layout:
            >
            > Column A Column B Column C
            > data 4 radio buttons more data
            > ... ... ...
            > ... ... ...
            >
            > The form does have a submit button that leads to a given CGI script.
            > The form also has submit buttons as onClick events inside of the radio
            > buttons, that point to a different CGI script. The problem is that I
            > need to know which particular radio button triggered the onClick
            > event, because when I receive the form data, I only want to process
            > the row of data for which an event was triggered. As the script is
            > now, I just receive everything from the form, without knowing which
            > row to actually process. The one thing I thought about trying was to
            > call a function with the onClick event that would receive a given row
            > id (1 through up to 279), and the use document.write to create a
            > hidden value for just that id. I don't know if this is workable,
            > though. Am I on the right track with this idea? Is this doable, or
            > should I think about trying a different approach?
            >
            > Thanks!!![/color]

            Comment

            • Steven Daedelus

              #7
              Re: Radio Submit Button Problem

              In article <40B83B59.50702 03@PointedEars. de>,
              Thomas 'PointedEars' Lahn <PointedEars@nu rfuerspam.de> wrote:
              [color=blue]
              > JR wrote:
              >[color=green]
              > > The form does have a submit button that leads to a given CGI script.
              > > The form also has submit buttons as onClick events inside of the radio
              > > buttons, that point to a different CGI script.[/color]
              >
              > What about users without support for client-side scripting?[/color]

              You can please all the people some of the time, and some of the people
              all the time, but you can't please all the people all the time.

              Comment

              • Matt Kruse

                #8
                Re: Radio Submit Button Problem

                Steven Daedelus wrote:[color=blue]
                > You can please all the people some of the time, and some of the people
                > all the time, but you can't please all the people all the time.[/color]

                Careful... uttering that truism around here can get you blacklisted ;)

                --
                Matt Kruse
                Javascript Toolbox: http://www.mattkruse.com/javascript/


                Comment

                • bruce

                  #9
                  Re: Radio Submit Button Problem

                  jrolandumuc@yah oo.com (JR) wrote in message news:<b386d54b. 0405271900.41e3 f35@posting.goo gle.com>...[color=blue]
                  > Hi. I hope someone out there who is more versed with JavaScript than
                  > I can help me with the following annoying problem. Here's the
                  > problem.
                  >
                  > I have a form with the following layout:
                  >
                  > Column A Column B Column C
                  > data 4 radio buttons more data
                  > ... ... ...
                  > ... ... ...
                  >
                  > The form does have a submit button that leads to a given CGI script.
                  > The form also has submit buttons as onClick events inside of the radio
                  > buttons, that point to a different CGI script. The problem is that I
                  > need to know which particular radio button triggered the onClick
                  > event, because when I receive the form data, I only want to process
                  > the row of data for which an event was triggered. As the script is
                  > now, I just receive everything from the form, without knowing which
                  > row to actually process. The one thing I thought about trying was to
                  > call a function with the onClick event that would receive a given row
                  > id (1 through up to 279), and the use document.write to create a
                  > hidden value for just that id. I don't know if this is workable,
                  > though. Am I on the right track with this idea? Is this doable, or
                  > should I think about trying a different approach?
                  >
                  > Thanks!!![/color]


                  Just capture whatever data you need inside hidden fields (be it
                  data, or id's, or names of controls, whatever), before you submit the
                  form.

                  Comment

                  • Steven Daedelus

                    #10
                    Re: Radio Submit Button Problem

                    In article <c9gt4c0oum@new s2.newsguy.com> ,
                    "Matt Kruse" <newsgroups@mat tkruse.com> wrote:
                    [color=blue]
                    > Steven Daedelus wrote:[color=green]
                    > > You can please all the people some of the time, and some of the people
                    > > all the time, but you can't please all the people all the time.[/color]
                    >
                    > Careful... uttering that truism around here can get you blacklisted ;)[/color]

                    I know it. It's just that sometimes I can't resist pointing out the
                    obvious...

                    Do you ever get the feeling that a lot of the most severe compliance
                    fascists don't have clients?

                    Comment

                    • Thomas 'PointedEars' Lahn

                      #11
                      Re: Radio Submit Button Problem

                      Steven Daedelus wrote:
                      [color=blue]
                      > In article <40B83B59.50702 03@PointedEars. de>,
                      > Thomas 'PointedEars' Lahn <PointedEars@nu rfuerspam.de> wrote:[/color]

                      Please do not write attribution novels, see e.g.
                      <http://www.holgermetzg er.de/netscape/usenet.html>
                      <http://netmeister.org/news/learn2quote.htm l>
                      [color=blue][color=green]
                      >> JR wrote:[color=darkred]
                      >> > The form does have a submit button that leads to a given CGI script.
                      >> > The form also has submit buttons as onClick events inside of the radio
                      >> > buttons, that point to a different CGI script.[/color]
                      >>
                      >> What about users without support for client-side scripting?[/color]
                      >
                      > You can please all the people some of the time, and some of the people
                      > all the time, but you can't please all the people all the time.[/color]

                      But you can do easily here.


                      PointedEars

                      Comment

                      • Thomas 'PointedEars' Lahn

                        #12
                        Re: Radio Submit Button Problem

                        Steven Daedelus wrote:
                        [color=blue]
                        > Do you ever get the feeling that a lot of the most severe compliance[/color]
                        ^^^^^^^^^^[color=blue]
                        > fascists don't have clients?[/color]
                        ^^^^^^^^
                        Godwin's Law. You lose.


                        PointedEars, F'up2 where it belongs

                        Comment

                        • JR

                          #13
                          Re: Radio Submit Button Problem

                          caoxuankien@hot mail.com (Kien) wrote in message news:<166d5d19. 0405291822.5351 2658@posting.go ogle.com>...[color=blue]
                          > </script>
                          >
                          > Maybe crude and very redundant but it's 7AM and my brain is not
                          > working ...
                          >
                          > HTH
                          >
                          > Kien[/color]

                          If it's crude and redundant, but works, I'm all for it! Thanks very
                          much for the solution. I found that the best solution for my
                          particular problem was right along the lines of your script. I call a
                          given function when the user selects a certain radio button, and pass
                          to this function data for only the row I want to process. I then
                          append this data string to my script path, i.e.
                          path/program.cgi?jav ascript_params, and then submit the form. This
                          way, I do get all of the data from the form when it is submitted, but
                          I know which row of data to process in the receiving script.

                          Thanks to everyone for the suggestions.

                          JR

                          Comment

                          • Dr John Stockton

                            #14
                            Re: Radio Submit Button Problem

                            JRS: In article <40BD1748.50606 @PointedEars.de >, seen in
                            news:comp.lang. javascript, Thomas 'PointedEars' Lahn
                            <PointedEars@nu rfuerspam.de> posted at Wed, 2 Jun 2004 01:54:48 :[color=blue]
                            >Steven Daedelus wrote:
                            >[color=green]
                            >> In article <40B83B59.50702 03@PointedEars. de>,
                            >> Thomas 'PointedEars' Lahn <PointedEars@nu rfuerspam.de> wrote:[/color]
                            >
                            >Please do not write attribution novels, see e.g.
                            ><http://www.holgermetzg er.de/netscape/usenet.html>
                            ><http://netmeister.org/news/learn2quote.htm l>[/color]



                            Son-of-RFC1036 (1994) refers to "attributio n lines" containing more
                            than just a name. Note the implication that more than one physical line
                            may be
                            needed.

                            A draft RFC by C H Lindsey (a well-known News expert), dated August
                            2002, envisages a line containing name, E-address, newsgroup, Message-
                            ID, date, and time; and that it may be folded. It is called draft-ietf-
                            usefor-article-08.txt

                            Therefore, your customary tedious insistence on minimal attributions is
                            contrary to respected recent thinking.

                            --
                            © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME ©
                            Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
                            Web <URL:http://www.merlyn.demo n.co.uk/news-use.htm> : about usage of News.
                            No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.

                            Comment

                            • Jeff Sandler

                              #15
                              Re: Radio Submit Button Problem

                              JR wrote:[color=blue]
                              > Hi. I hope someone out there who is more versed with JavaScript than
                              > I can help me with the following annoying problem. Here's the
                              > problem.
                              >
                              > I have a form with the following layout:
                              >
                              > Column A Column B Column C
                              > data 4 radio buttons more data
                              > ... ... ...
                              > ... ... ...
                              >
                              > The form does have a submit button that leads to a given CGI script.
                              > The form also has submit buttons as onClick events inside of the radio
                              > buttons, that point to a different CGI script. The problem is that I
                              > need to know which particular radio button triggered the onClick
                              > event, because when I receive the form data, I only want to process
                              > the row of data for which an event was triggered. As the script is
                              > now, I just receive everything from the form, without knowing which
                              > row to actually process. The one thing I thought about trying was to
                              > call a function with the onClick event that would receive a given row
                              > id (1 through up to 279), and the use document.write to create a
                              > hidden value for just that id. I don't know if this is workable,
                              > though. Am I on the right track with this idea? Is this doable, or
                              > should I think about trying a different approach?
                              >
                              > Thanks!!![/color]
                              Since this conversation seems to have drifted from the point, I'll do my
                              part to direct it back.

                              Message author bruce seemed to have the answer to the original question
                              which allows JR to keep his form as it is. I intend to include code
                              (not tested, just making it up as I type) to support bruce's idea.


                              <head>....
                              <script>
                              function testButtons(but tonArray)
                              {
                              len = buttonArray.len gth
                              for(i=0;i<len;i ++)
                              {
                              if(buttonArray[i].checked)
                              {
                              widelyVisibleVa riable = i;
                              return true;
                              {
                              }
                              }
                              </script>
                              ......</head>

                              <body>
                              ....
                              <form name=someName action=someServ er onSubmit=testBu ttons(buttonGro upName)>
                              ....
                              </form>
                              </body>

                              Comment

                              Working...