HREF within a FORM

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bforward@texarkanacollege.edu

    HREF within a FORM

    I want to give the user two display choices with radio buttons at the
    top of the page. Then I want to provide a series of HREF type links for
    them to click on for the choice made. Is it possible to mix HREF links
    with FORM radio buttons so that when the user clicks on the HREF link,
    one of the radio button choices is included in the GET or POST data
    sent to the next URL?

  • kaeli

    #2
    Re: HREF within a FORM

    In article <1113406592.248 773.38170@l41g2 000cwc.googlegr oups.com>,
    bforward@texark anacollege.edu enlightened us with...[color=blue]
    > I want to give the user two display choices with radio buttons at the
    > top of the page. Then I want to provide a series of HREF type links for
    > them to click on for the choice made. Is it possible to mix HREF links
    > with FORM radio buttons so that when the user clicks on the HREF link,
    > one of the radio button choices is included in the GET or POST data
    > sent to the next URL?
    >
    >[/color]

    Yes and no.
    Javascript when the text is clicked instead of using an actual href, more
    than likely.

    Be more specific about what you're trying to accomplish and the architecture
    of the application / pages.
    There are always lots of ways to do things -- you want to chose the best way
    for what you're doing.

    --
    --
    ~kaeli~
    She was engaged to a boyfriend with a wooden leg but broke
    it off.



    Comment

    • bforward@texarkanacollege.edu

      #3
      Re: HREF within a FORM

      Here's what I want to do:
      -------------------------------------------------------------
      <form "myform">
      Click here for choice 1<input type="radio" name="choice" >
      Click here for choice 2<input type="radio" name="choice" >

      ....later in the HTML code...

      <a href="nextcgi.c gi?choicemade=* &otherdata=xyz> Click here to see the
      results of your choice for xyz</a>

      <a href="nextcgi.c gi?choicemade=* ,otherdata=abc> Click here to see the
      results of your choice for abc</a>

      ....there could be a lot of these href links ...

      -----------------------------------------------------------
      See where the asterisk is after "choicemade =" in the href
      link?...that's where I want to substitute something that indicates
      which radio button was pressed. I may need a javascript function, but
      I'm not sure exactly how to implement it.

      Comment

      • kaeli

        #4
        Re: HREF within a FORM

        In article <1113420250.406 921.75500@f14g2 000cwb.googlegr oups.com>,
        bforward@texark anacollege.edu enlightened us with...[color=blue]
        > Here's what I want to do:
        > -------------------------------------------------------------
        > <form "myform">
        > Click here for choice 1<input type="radio" name="choice" >
        > Click here for choice 2<input type="radio" name="choice" >
        >
        > ...later in the HTML code...
        >
        > <a href="nextcgi.c gi?choicemade=* &otherdata=xyz> Click here to see the
        > results of your choice for xyz</a>
        >
        > <a href="nextcgi.c gi?choicemade=* ,otherdata=abc> Click here to see the
        > results of your choice for abc</a>
        >
        > ...there could be a lot of these href links ...
        >
        > -----------------------------------------------------------
        > See where the asterisk is after "choicemade =" in the href
        > link?...that's where I want to substitute something that indicates
        > which radio button was pressed. I may need a javascript function, but
        > I'm not sure exactly how to implement it.[/color]

        Okay, is this carved into stone?

        Because what I'm seeing here is that you want some clickable text that takes
        a user to another page that is always the same page, but with different GET
        params. How many more parameters are actually in the real code? If it is just
        this one, than a simple solution would be to put that in a hidden form field
        instead of the url and have the clickable text change the form field value
        and submit the form as GET, putting the values in the URL.

        This would create a javascript dependency. If your users may not have
        javascript, you should at least have a fallback "noscript" page or something
        to direct them to, i.e.
        <a href="noscript. html" onClick="go(abc ); return false;">Click here to see
        the results of your choice for abc</a>

        --
        --
        ~kaeli~
        Profanity: the single language in which all programmers are
        expert.



        Comment

        • bforward@texarkanacollege.edu

          #5
          Re: HREF within a FORM

          Here is exactly what I want to do:
          -------------------------------------------------------------------
          <head>
          <title>Test HREF with RADIO buttons</title>

          <SCRIPT LANGUAGE="JavaS cript">
          <!--
          function WhichButton()
          {
          var choice1 = eval("document. myform.choice[0].checked")
          var choice2 = eval("document. myform.choice[1].checked")

          if (choice1 == true) return 1
          else return 2
          }
          //-->
          </SCRIPT>

          </head>

          <form "myform">
          Click here for choice 1<input type="radio" name="choice" value=1><br>
          Click here for choice 2<input type="radio" name="choice" value=2><br>

          <hr>
          <a href="next.cgi? code=javascript :WhichButton()& other=abc">ABC</a><br>
          <a href="next.cgi? code=javascript :WhichButton()& other=xyz">XYZ</a><br>

          <! ...there will be many more href tags here...>

          <hr>

          </form>

          -------------------------------------------------------------------
          There will be only two radio buttons at the top of the displayed page.
          There could be many href tags, each with different "other" values.

          In the href tag, see where I try to invoke the javascript function
          WhichButton()? Well, that is where I want to have it substitute the
          value 1 or 2 returned from the function so that it sends
          "next.cgi?code= 1&other=abc" if the user clicks on the first link after
          first choosing radio button 1,
          or
          "next.cgi?code= 2&other=abc" if the user clicks on the first link after
          first choosing radio button 2.

          Comment

          • kaeli

            #6
            Re: HREF within a FORM

            In article <1113424705.467 547.59690@o13g2 000cwo.googlegr oups.com>,
            bforward@texark anacollege.edu enlightened us with...[color=blue]
            > Here is exactly what I want to do:
            > -------------------------------------------------------------------
            > <head>
            > <title>Test HREF with RADIO buttons</title>
            >
            > <SCRIPT LANGUAGE="JavaS cript">[/color]

            <script type="text/javascript">
            Language attribute is deprecated.
            [color=blue]
            > <!--[/color]

            Don't need to comment it out any more. That went out of need with Netscape 3
            or some such.
            Just extra bytes in a file now.
            [color=blue]
            > function WhichButton()
            > {
            > var choice1 = eval("document. myform.choice[0].checked")[/color]

            Eeek!
            Eval is Evil. ;)
            choice1 = document.myform .choice[0].checked;
            should be just fine. The checked property is true or false anyway. No need
            for eval. Actually, there is very, very rarely a need for the resource
            glutton that is called eval.

            Actually, see script below. You don't need it at all.
            [color=blue]
            > <a href="next.cgi? code=javascript :WhichButton()& other=abc">ABC</a><br>[/color]

            Unfortunately, you can't do this.
            As long as you're using javascript, do it all the way. ;)

            I assume from your post that there is always only one 'other' value and it's
            the only additional parameter.
            Also note that radio buttons mean you always expect one value. That means one
            should be checked by default. So I put that here.

            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
            "http://www.w3.org/TR/html4/loose.dtd">
            <html>
            <head>
            <title> New Document </title>
            </head>

            <body>
            <script type="text/javascript">
            function go(otherval)
            {
            document.myform .other.value=ot herval;
            document.myform .submit();
            }
            </script>

            </head>

            <form name="myform" action="next.cg i" method="get">
            Choice 1<input type="radio" name="choice" value=1 checked><br>
            Choice 2<input type="radio" name="choice" value=2><br>
            <input type="hidden" name="other" value="">
            </form>

            <hr>
            <a href="#" onClick="go('ab c'); return false;">ABC</a><br>
            <a href="#" onClick="go('xy z'); return false;">XYZ</a><br>
            <hr>

            </body>
            </html>


            --
            --
            ~kaeli~
            Reading while sunbathing makes you well red.



            Comment

            • bforward@texarkanacollege.edu

              #7
              Re: HREF within a FORM

              Thanks for your help--I figured it out.

              Comment

              Working...