#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    31
    Rep Power
    2

    Radio_group button doesn't work


    I want toshow two radio buttons of gender for a student. I want to update the value of this radio button but the problem is that doesn' appears the button but just the label.
    Code:
        $cInput_form .= $q->div({-class => 'control-group'},
        	                $q->label({-class => 'control-label', -for => 'gender'}, "Gender:"), 
        	                $q->div({class => 'controls'}, 
        	                $q->span({class => 'span12'},
        	                $q->label({-class => 'blue'},
        	                $q->radio_group({-id => 'gender',name => 'gender', -values => ['M','F'], -labels => \%labels, -default => $cGender, 'true'}), $q->span({-class => 'lbl'})))));
    And this is what it shows when "Inspect Elements"

    Code:
        <div class="control-group">
          <label class="control-label" for="gender">Gender:</label>
          <div class="controls">
            <span class="span12">
              <label class="blue">
                <label>
                  <input type="radio" name="gender" value="M" checked="checked" id="gender" true="">
                  Male
                </label>
                <label>
                  <input type="radio" name="gender" value="F" id="gender" true="">
                  Female
                </label>
                <span class="lbl"></span>
              </label>
            </span>
          </div>
        </div>
    I think the problem is that `<span class = 'lbl'>` is not in the right place. But i dont know where to put it else. Please i need some help


    The problem is that
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,940
    Rep Power
    1225
    Why are you trying to use a radio group as the value for a label? Is that what you really intended?

    Since you already have a "Gender" label, I don't see the need for the second label and would remove it. You should also fix your indentation so that the parent/child relationships are clear.

    Code:
        $cInput_form .= $q->div({-class => 'control-group'},
                                $q->span({-class => 'lbl'},
                                         $q->label({-class => 'control-label', -for => 'gender'}, "Gender:"),
                                         $q->div({class => 'controls'},
                                                 $q->span({class => 'span12'},
                                                          $q->radio_group({-id => 'gender',
                                                                           -name => 'gender',
                                                                           -values => ['M','F'],
                                                                           -labels => \%labels,
                                                                           -default => $cGender, 'true'}
                                                                          ),
                                                          )
                                                 )
                                        )
                                );
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    31
    Rep Power
    2
    It still doesn't work! Just shows:
    M
    F without buttons
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,940
    Rep Power
    1225
    Try this:
    Code:
    $q->radio_group(
                 -name => 'gender',
                 -values => ['M','F'],
                 -default => $cGender,
                 -linebreak => 'true',
                 -labels => \%labels,
                 -attributes  => { id => 'gender' }
                ),
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    31
    Rep Power
    2
    I don't understand why it doesn't works. It still shows me the labels without buttons
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,940
    Rep Power
    1225
    Please post a short but complete script that includes my suggested code changes and demonstrates your problem.

    It's been a long time since I created a radio group with the CGI module, so my first post assumed that you were using the correct syntax, which you weren't. After reviewing the docs I remembered that the radio_group() method expects you to pass an ordered list of params, not a hash ref like you were sending. The last code snippet I posted uses the syntax shown in the docs and will work assuming the syntax of the surrounding nested code is correct. I did not test that code, so that surrounding code may be wrong.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    31
    Rep Power
    2
    Code:
    $cInput_form .= $q->div({-class => 'control-group'},
                                $q->span({-class => 'lbl'},
                                         $q->label({-class => 'control-label', -for => 'gender'}, "Gender:"),
                                         $q->div({class => 'controls'},
                                                 $q->span({class => 'span12'},
                                                          $q->radio_group(
    																	 -name => 'gender',
    																	 -values => ['M','F'],
    																	 -default => $cGender,
    																	 -linebreak => 'true',
    																	 -labels => \%labels,
    																	 -attributes  => { id => 'gender' }
    																	),
                                                          )
                                                 )
                                        )
                                );
    I think the problem is at span, because it appears to be outside label. It is like this :
    Code:
    <div class="control-group"><span class="lbl"><label class="control-label" for="gener">Gender:</label> <div class="controls"><span class="span12"><label><input type="radio" name="gender" value="M">Male</label><br> <label><input type="radio" name="gender" value="F">Female</label><br></span></div></span></div>
    and should be like this :
    Code:
    <div class="control-group"><label class="control-label" for="gender">Gender:</label> <div class="controls"><span class="span12"><label class="blue"><label><input type="radio" name="gender" value="M" checked="checked" true=""><span class="lbl">Male</span></label> <label><input type="radio" name="gender" value="F" true=""><span class="lbl">Female</span></label></label></span></div></div>
    Last edited by laua; August 19th, 2013 at 02:26 AM.
  14. #8
  15. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,262
    Rep Power
    1810
    Using CGI.pm to create complex HTML isn't really the best way to go about it. Consider using this syntax:

    Code:
    print $q->span({-class => 'lbl'}, ... );
    vs.

    Code:
    print '<span class="lbl"> ... </lbl>';
    Nothing is really gained, and you've made your code much more complex.

    In this example I would use straight HTML in a string or heredoc, and only use CGI.pm for whatever is variable.

    And usually, once it reaches this level of complexity, I'd begin using a template.

    By the way, you can make the code simpler by exporting :standard from CGI.pm. That would allow you to simply print 'div', rather than '$q->div'
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,940
    Rep Power
    1225
    I can't do any testing until latter today, but it appears that you're missing some commas which could be causing the problem.

    Personally, I'd would not manually create the html like this. I'd use one of the template modules, such as HTML::Template. That would solve lots of problems.

IMN logo majestic logo threadwatch logo seochat tools logo