enable/disable radio buttons

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pradeepjain
    Contributor
    • Jul 2007
    • 563

    enable/disable radio buttons

    Code:
    for($i = 1; $i <= 15 ; $i++){
    for($k = 1; $k <= 10 ; $k++){
    $myresult .= "<input class='star' type='radio' name='rating".$i."' id='rating".$i."' value='". $k ."' disabled='true'  $chk  title='". $k." out of 10 ' />";
    }
    }
    $myresult .= "<a href='#' id=\"rate-it\" onclick=\"test('rating".$i."');\">Rate It</a>";
    <script type='text/javascript'>
    function test(name){
            document.ratings.rating1.disabled = false;
            document.ratings.rating2.disabled = false;
            document.ratings.rating3.disabled = false;
    alert('hai');
    }
    hi i am working on a product site where in i display 10 radio button for 15 features of a product for user to rate . and each check box is disabled by default and i add a rate it button "rate-it" which on click should enable 1 row of checkboxes . i tried to write code for tht . its print the alert msg and all. but enabling the checkboxes is not working any help on it!?
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    Hi,
    This is a sample code....

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <META NAME="Generator" CONTENT="EditPlus">
    <META NAME="Author" CONTENT="">
    <META NAME="Keywords" CONTENT="">
    <META NAME="Description" CONTENT="">
    <script type="text/javascript">
    function enableRadio(rdId)
    {
    	//alert(rdId);
    	document.getElementById(rdId).disabled=false;
    }
    </script>
    </HEAD>
    
    <BODY>
    <input type="radio" name="demoRadio" id="demoRadio" disabled="disabled"/>
    <input type="button" value="Enable It" onclick="enableRadio('demoRadio')">
    </BODY>
    </HTML>
    Thanks and Regards
    Ramanan Kalirajan

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      though this demo should work, it is not a solution to the question.

      there are some questions, that should be answered beforehand.

      mainly, your code does not match your description in any way:
      - are you using checkboxes (as in the description) or radio buttons (as in the code)?
      - do you want to rate it with a button (as in the description) or via link (as in the code)?
      - your test function’s parameter is used nowhere
      - should the radios be grouped (aka same name)?

      Standardista’s corner:
      Code:
      <input type="radio" name="demoRadio" id="demoRadio" disabled="disabled"/>
      should be
      Code:
      <INPUT type="radio" name="demoRadio" id="demoRadio" disabled>
      in HTML 4.01 (although it is not treated as error)

      as a general rule of thumb, write your code consequently in one style, e.g. all tag names upper case and all attribute names lowercase. makes up for a better reading experience (especially for those people, who shall have a look at your code later)

      Comment

      • pradeepjain
        Contributor
        • Jul 2007
        • 563

        #4
        1)- are you using checkboxes (as in the description) or radio buttons (as in the code)?
        2)- do you want to rate it with a button (as in the description) or via link (as in the code)?
        3)- your test function’s parameter is used nowhere
        4)- should the radios be grouped (aka same name)?
        1) sorry for that error its radio buttons that i am using.
        2) once he clicks on link/button the disabled property must get enabled . well it is a link as in the code.
        3)sorry i had hardcoded the values in the test function to check the function
        4) yeah a set of 10 radio buttons in a same row with same name .

        Comment

        • pradeepjain
          Contributor
          • Jul 2007
          • 563

          #5
          here is an improved version of ma code

          Code:
           for($i = 1; $i <= 15 ; $i++){
           for($k = 1; $k <= 10 ; $k++){
           $myresult .= "<input class='star' type='radio' name='rating".$i."' id='rating".$i."' value='". $k ."' disabled='true'  $chk  title='". $k." out of 10 ' />";
           }
           }
          $myresult .= "<a href='#' id=\"rate-it\" onclick=\"test('rating".$i."');\">Rate It</a>";
          
          <script type='text/javascript'>
          function test(name){
          
          //for (i=1; i<=10; i++){
          //  document.getElementById(name[i]).disabled=false; // tried this with the for loop..but error console gave an error like document.getElementById(name[i]) is NULL
            document.getElementById(name).disabled=false;
          //}
              
          alert(name);
          }
              </script>
          but still the enabling of the radio buttons is not working !

          Comment

          • RamananKalirajan
            Contributor
            • Mar 2008
            • 608

            #6
            @pradeepjain

            Code:
            $myresult .= "<a href='#' id=\"rate-it\" onclick=\"test('rating".$i."');\">Rate It</a>";
            In the above code "$i" is out of the loop. Where "i" is the loop index. Try to give this inside the loop or change the logic. As the "i" variable is holding juck data, it is not working for you.

            @Dormilich
            Attribute Minimization is not a good practice in XHTML 1.0. Is it ok to give like that. I will follow the code standards - all tag names upper case and all attribute names lowercase. Thanks for the information.

            Thanks and Regards
            Ramanan Kalirajan

            Comment

            • pradeepjain
              Contributor
              • Jul 2007
              • 563

              #7
              Code:
               for($i = 1; $i <= 15 ; $i++){
               for($k = 1; $k <= 10 ; $k++){
               $myresult .= "<input class='star' type='radio' name='rating".$i."' id='rating".$i."' value='". $k ."' disabled='true'  $chk  title='". $k." out of 10 ' />";
               }
              $myresult .= "<a href='#' id=\"rate-it\" onclick=\"test('rating".$i."');\">Rate It</a>";
               }
              
               
              <script type='text/javascript'>
              function test(name){
               
              //for (i=1; i<=10; i++){
              //  document.getElementById(name[i]).disabled=false; // tried this with the for loop..but error console gave an error like document.getElementById(name[i]) is NULL
                document.getElementById(name).disabled=false;
              //}
               
              alert(name);
              }
                  </script>

              sorry for ma error..i wrote the code by hand over here so that cane out of the for loop. but then also its not working . in the javascript i have shown a for loop thing which i tried earlier but it gave the error which i have given over there .

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                @pradeepjain

                one of your core problems is, that you use multiple IDs, where they should be unique.

                @RamananKaliraj an

                I was not talking about XHTML (because hardly anyone really uses it). if you were to use XHTML and to use the XML parser (most people use the HTML parser), you’d be prompted with every mistake.

                Comment

                • pradeepjain
                  Contributor
                  • Jul 2007
                  • 563

                  #9
                  i will tell u the exact requirement .

                  each row will have 10 radio buttons in which only 1 can be clicked at 1 time . so like this there will be 7 rows like this . each row of radio buttons have a unique ID like rating1..rating 7 . so when i click on a rate-it link on each row tht row disabled property must get cancelled and the radio buttons must get enabled .

                  hope i made the concept clear and logic is correct also!!

                  Comment

                  • Dormilich
                    Recognized Expert Expert
                    • Aug 2008
                    • 8694

                    #10
                    each row of radio buttons have a unique ID like rating1..rating 7
                    this is where your code fails.

                    Comment

                    • pradeepjain
                      Contributor
                      • Jul 2007
                      • 563

                      #11
                      you mean to say each radio button should have a diff id like rating11,rating 12 for 1st row and rating21,rating 22 for second row!!

                      Comment

                      • Dormilich
                        Recognized Expert Expert
                        • Aug 2008
                        • 8694

                        #12
                        jepp, as demanded by the DTD.

                        Comment

                        • pradeepjain
                          Contributor
                          • Jul 2007
                          • 563

                          #13
                          okie i did that and it worked ,, i tried to apply some jquery to it .. when its applied it stops working . but without the jquery it works f9!

                          Code:
                          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
                          <HTML>
                          <HEAD>
                          <TITLE> New Document </TITLE>
                          <META NAME="Generator" CONTENT="EditPlus">
                          <META NAME="Author" CONTENT="">
                          <META NAME="Keywords" CONTENT="">
                          <META NAME="Description" CONTENT="">
                          <script src="jquery.js" type="text/javascript" language="javascript"></script>
                          <script src="jquery.rating.js" type="text/javascript" language="javascript"></script>
                                  <link href="jquery.rating.css" type="text/css" rel="stylesheet"/>
                          
                          <script type="text/javascript">
                          function test(name)
                          {
                              alert(name);
                             for (k=1; k<=10; k++){
                              document.getElementById(name+k).disabled=false;
                          }
                          }
                          </script>
                          </HEAD>
                          
                          <BODY>
                          <?php
                          for($i = 1; $i <= 15 ; $i++){
                           for($k = 1; $k <= 10 ; $k++){
                           $myresult .= "<input class='star' type='radio' name='rating".$i."' id='rating".$i."".$k."' value='". $k ."' disabled='true'  $chk  title='". $k." out of 10 ' />";
                           }
                          $myresult .= "<a href='#' id=\"rate-it\" onclick=\"test('rating".$i."');\">Rate It</a><br/>";
                           }
                          echo $myresult;
                           ?>
                          </BODY>
                          </HTML>
                          and the jquery.rating.j s, jquery.rating.c ss are taken form the below site .

                          jQuery Star Rating Plugin. Contribute to fyneworks/star-rating development by creating an account on GitHub.

                          Comment

                          • pradeepjain
                            Contributor
                            • Jul 2007
                            • 563

                            #14
                            is there no solution for this or has no1 looked at this problem?

                            Comment

                            • Dormilich
                              Recognized Expert Expert
                              • Aug 2008
                              • 8694

                              #15
                              my problem is, that I don’t know jQuery.

                              Comment

                              Working...