Programmatically setting a radio buttones

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

    #1

    Programmatically setting a radio buttones

    I am trying to programmaticall y set a radio button in a table of radio
    buttons. I have two problems with the code below:

    1 - I can not prepare the <Formstatemen t to be printed by php.
    (syntax of the hyphens, quotes) my fault!

    2 - If I delete the <Formand </Formstatements I can build the table
    of radio buttons correctly, HTML wise. The fifth radio button has
    'checked=True'. The problem is even though I set radio button 5 to be
    checked only the last radio button is checked when it is displayed on
    the screen. But viewing the page code says it should be the fifth radio
    button.

    Anybody have some ideas, I'm lost.

    <?php
    /**

    */
    if(isset($_POST['abbr_letter']) ) {
    $selectedNum = $_POST['abbr_letter'];
    }
    else {
    $selectedNum = 1;
    }

    $value = 0;
    $checked = 'false';
    $selectedNum = 5;
    $ColumBrake = 13;

    print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">';
    print '<html xmlns="http://www.w3.org/1999/xhtml">';
    print '<HTML>';
    print '<HEAD>';
    print '<title>Testiin g radio Buttons</title>';
    print '<link href="quotes.cs s" rel="stylesheet " type="text/css">';
    print '<SCRIPT language=JavaSc ript src="quotesCss. js"
    type="text/javascript"></SCRIPT>';
    // print '<b><FORM NAME="author_ab brv" method="POST" action="'.<?php
    echo $_SERVER['PHP_SELF'];?>.'"></b>';
    print '</HEAD>';
    print '<table><tbody> <tr>';

    foreach (range('A', 'Z') as $letter)
    {
    if( $value == $ColumBrake) {
    print '</tr><tr>';
    }
    if( $value == $selectedNum) {
    $checked = 'true';
    print '<td><input type="radio" name="abbr_lett er" value="'.
    $value .'" checked="'. $checked .
    '" onclick="submit ()" />'.$letter.'</td>';
    } else {
    $checked = 'false';
    print '<td><input type="radio" name="abbr_lett er" value="'.
    $value .'" checked="'. $checked .
    '" onclick="submit ()" />'.$letter.'</td>';
    }
    $value = $value +1;
    }
    print '</tr></tbody></table>';
    // print '</FORM>';
    print '</HTML>';
    ?>

    --
    Thanks in Advance... http://ichbin.9999mb.com
    IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
    _______________ _______________ _______________ _______________ __________
    'If there is one, Knowledge is the "Fountain of Youth"'
    -William E. Taylor, Regular Guy (1952-)
  • Geoff Berrow

    #2
    Re: Programmaticall y setting a radio buttones

    Message-ID: <x_-cnfV-DsKWwf_YUSdV9g@ ptd.netfrom IchBin contained the
    following:
    >I am trying to programmaticall y set a radio button in a table of radio
    >buttons. I have two problems with the code below:
    >
    >1 - I can not prepare the <Formstatemen t to be printed by php.
    >(syntax of the hyphens, quotes) my fault!
    >// print '<b><FORM NAME="author_ab brv" method="POST" action="'.<?php
    >echo $_SERVER['PHP_SELF'];?>.'"></b>';

    print '<b><FORM NAME="author_ab brv" method="POST" action="'.
    $_SERVER['PHP_SELF'].'"></b>';
    --
    Geoff Berrow (put thecat out to email)
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs http://www.ckdog.co.uk/rfdmaker/

    Comment

    • Kimmo Laine

      #3
      Re: Programmaticall y setting a radio buttones

      "IchBin" <weconsul@ptd.n etwrote in message
      news:x_-cnfV-DsKWwf_YUSdV9g@ ptd.net...
      >I am trying to programmaticall y set a radio button in a table of radio
      >buttons. I have two problems with the code below:
      >
      1 - I can not prepare the <Formstatemen t to be printed by php. (syntax
      of the hyphens, quotes) my fault!
      >
      2 - If I delete the <Formand </Formstatements I can build the table
      of radio buttons correctly, HTML wise. The fifth radio button has
      'checked=True'. The problem is even though I set radio button 5 to be
      checked only the last radio button is checked when it is displayed on the
      screen. But viewing the page code says it should be the fifth radio
      button.
      >
      Anybody have some ideas, I'm lost.


      You're not using the checked attribute correctly. It has no value true or
      false. If you wish to assign a value to it (in xhtml you MUST assign a value
      to it) the value is "checked". However the value is not evaluated ever, it's
      just a dummy placeholder. Just the presence of the checked attribute means
      that the button should be checked, weather it's value is set to "true",
      "false" or "barbara streisand". When you have a zillion buttons that all are
      checked, the last one remains checked. This is what you are experiecing

      right:
      <input type="radio" name="foo" checked="checke d" />
      <input type="radio" name="foo" />
      <input type="radio" name="foo" />

      wrong:
      <input type="radio" name="foo" checked="true" />
      <input type="radio" name="foo" checked="false" />
      <input type="radio" name="foo" checked="donald duck" />
      (All are checked)

      Only set the checked attiribute to the element you want checked, and it's
      value should be "checked", and not set it to any of the other elements.

      --
      "Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
      http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
      spam@outolempi. net | rot13(xvzzb@bhg byrzcv.arg)


      Comment

      • Shelly

        #4
        Re: Programmaticall y setting a radio buttones


        "Kimmo Laine" <spam@outolempi .netwrote in message
        news:Cmy8h.5681 0$Ef4.19390@rea der1.news.jippi i.net...
        right:
        <input type="radio" name="foo" checked="checke d" />
        <input type="radio" name="foo" />
        <input type="radio" name="foo" />
        I do it this way:

        <input type="radio" name="foo" <?php if (some_condition _is_met) echo "
        checked"; ?/>

        I don't put in checked="checke d", I simply put in checked.

        Shelly


        Comment

        • Kimmo Laine

          #5
          Re: Programmaticall y setting a radio buttones

          "Shelly" <sheldonlg.news @asap-consult.comwrot e in message
          news:YkC8h.1707 $ql2.1125@newsr ead3.news.pas.e arthlink.net...
          >
          "Kimmo Laine" <spam@outolempi .netwrote in message
          news:Cmy8h.5681 0$Ef4.19390@rea der1.news.jippi i.net...
          >right:
          ><input type="radio" name="foo" checked="checke d" />
          ><input type="radio" name="foo" />
          ><input type="radio" name="foo" />
          >
          I do it this way:
          >
          <input type="radio" name="foo" <?php if (some_condition _is_met) echo "
          checked"; ?/>
          >
          I don't put in checked="checke d", I simply put in checked.

          That works perfectly if you're using an html 4.01 doctype, there's nothing
          wrong with that. But as I mentioned, in xhtml an attribute is required to
          have a value, and that's why one must use checked="checke d" when working
          with xhtml doctype. This is explained briefly in the w3c xhtml
          documentation: http://www.w3.org/TR/xhtml1/#h-4.5

          --
          "Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
          http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
          spam@outolempi. net | rot13(xvzzb@bhg byrzcv.arg)


          Comment

          • IchBin

            #6
            Re: Programmaticall y setting a radio buttones

            Kimmo Laine wrote:
            "Shelly" <sheldonlg.news @asap-consult.comwrot e in message
            news:YkC8h.1707 $ql2.1125@newsr ead3.news.pas.e arthlink.net...
            >"Kimmo Laine" <spam@outolempi .netwrote in message
            >news:Cmy8h.568 10$Ef4.19390@re ader1.news.jipp ii.net...
            >>right:
            >><input type="radio" name="foo" checked="checke d" />
            >><input type="radio" name="foo" />
            >><input type="radio" name="foo" />
            >I do it this way:
            >>
            ><input type="radio" name="foo" <?php if (some_condition _is_met) echo "
            >checked"; ?/>
            >>
            >I don't put in checked="checke d", I simply put in checked.
            >
            >
            That works perfectly if you're using an html 4.01 doctype, there's nothing
            wrong with that. But as I mentioned, in xhtml an attribute is required to
            have a value, and that's why one must use checked="checke d" when working
            with xhtml doctype. This is explained briefly in the w3c xhtml
            documentation: http://www.w3.org/TR/xhtml1/#h-4.5
            >
            Thank you Kimmo and Shelly for your help. Not sure where I got the idea
            of true or false but then again I am very new to this type of coding. So
            anything is possible on my side of the house.

            --
            Thanks in Advance... http://ichbin.9999mb.com
            IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
            _______________ _______________ _______________ _______________ __________
            'If there is one, Knowledge is the "Fountain of Youth"'
            -William E. Taylor, Regular Guy (1952-)

            Comment

            • Shelly

              #7
              Re: Programmaticall y setting a radio buttones


              "IchBin" <weconsul@ptd.n etwrote in message
              news:OgedneOKI4 8Y3v7YUSdV9g@pt d.net...
              Kimmo Laine wrote:
              >"Shelly" <sheldonlg.news @asap-consult.comwrot e in message
              >news:YkC8h.170 7$ql2.1125@news read3.news.pas. earthlink.net.. .
              >>"Kimmo Laine" <spam@outolempi .netwrote in message
              >>news:Cmy8h.56 810$Ef4.19390@r eader1.news.jip pii.net...
              >>>right:
              >>><input type="radio" name="foo" checked="checke d" />
              >>><input type="radio" name="foo" />
              >>><input type="radio" name="foo" />
              >>I do it this way:
              >>>
              >><input type="radio" name="foo" <?php if (some_condition _is_met) echo "
              >>checked"; ?/>
              >>>
              >>I don't put in checked="checke d", I simply put in checked.
              >>
              >>
              >That works perfectly if you're using an html 4.01 doctype, there's
              >nothing wrong with that. But as I mentioned, in xhtml an attribute is
              >required to have a value, and that's why one must use checked="checke d"
              >when working with xhtml doctype. This is explained briefly in the w3c
              >xhtml documentation: http://www.w3.org/TR/xhtml1/#h-4.5
              >>
              Thanks Kimmo. I wasn't aware there might be a problem as this has always
              worked for me.

              Shelly


              Comment

              • IchBin

                #8
                Re: Programmaticall y setting a radio buttones

                Geoff Berrow wrote:
                Message-ID: <x_-cnfV-DsKWwf_YUSdV9g@ ptd.netfrom IchBin contained the
                following:
                >
                >I am trying to programmaticall y set a radio button in a table of radio
                >buttons. I have two problems with the code below:
                >>
                >1 - I can not prepare the <Formstatemen t to be printed by php.
                >(syntax of the hyphens, quotes) my fault!
                >
                >
                >// print '<b><FORM NAME="author_ab brv" method="POST" action="'.<?php
                >echo $_SERVER['PHP_SELF'];?>.'"></b>';
                >
                >
                print '<b><FORM NAME="author_ab brv" method="POST" action="'.
                $_SERVER['PHP_SELF'].'"></b>';
                Thanks Geoff, sorry I missed your response. I did look at the code again
                and realized what I was doing wrong. Not used to these scripting languages.

                --
                Thanks in Advance... http://ichbin.9999mb.com
                IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
                _______________ _______________ _______________ _______________ __________
                'If there is one, Knowledge is the "Fountain of Youth"'
                -William E. Taylor, Regular Guy (1952-)

                Comment

                Working...