Home: Perl Programming Help: Intermediate:
CGI.pm radio button doesn't support "id" ?



ningji
User

May 13, 2014, 3:12 PM


Views: 12558
CGI.pm radio button doesn't support "id" ?

id is used for CSS and JavaScript/jQuery (has to be unique in a page),

but in my perl 5.14.2, seems CGI.pm doesn't support "id" ?
am i missing something or ?

Thanks !


FishMonger
Veteran / Moderator

May 13, 2014, 4:50 PM


Views: 12524
Re: [ningji] CGI.pm radio button doesn't support "id" ?

You should ALWAYS post the relevant code.

Did you specify the -labelattributes parameter?


FishMonger
Veteran / Moderator

May 13, 2014, 4:59 PM


Views: 12517
Re: [ningji] CGI.pm radio button doesn't support "id" ?

In case you didn't understand what I was referring to, here's an example.


Code
#!/usr/bin/perl 

use strict;
use warnings;
use CGI qw(:standard);
use CGI::Pretty;

print header(),
start_html(),
radio_group(-name => 'group_name',
-values => ['eenie', 'meenie', 'minie'],
-default => 'meenie',
-labelattributes => { id => 'my_id' }),
end_html();



ningji
User

May 13, 2014, 5:04 PM


Views: 12513
Re: [FishMonger] CGI.pm radio button doesn't support "id" ?

Thanks so much !

(the next time i'll remember to post my code)


FishMonger
Veteran / Moderator

May 13, 2014, 5:16 PM


Views: 12504
Re: [ningji] CGI.pm radio button doesn't support "id" ?

I used the id attribute because that's what you referred to in your question, but in this case you should instead use the class attribute.


ningji
User

May 13, 2014, 5:16 PM


Views: 12503
Re: [FishMonger] CGI.pm radio button doesn't support "id" ?

1 more question, in your example,
if i want each of the radio has its own id,
how should i write it ?

-labelattributes => { id => ['id1', 'id2'] }),



In Reply To
In case you didn't understand what I was referring to, here's an example.


Code
#!/usr/bin/perl 

use strict;
use warnings;
use CGI qw(:standard);
use CGI::Pretty;

print header(),
start_html(),
radio_group(-name => 'group_name',
-values => ['eenie', 'meenie', 'minie'],
-default => 'meenie',
-labelattributes => { id => 'my_id' }),
end_html();




(This post was edited by ningji on May 13, 2014, 5:18 PM)


FishMonger
Veteran / Moderator

May 13, 2014, 5:34 PM


Views: 12485
Re: [ningji] CGI.pm radio button doesn't support "id" ?

You'll probably need to print each radio button individually.


ningji
User

May 13, 2014, 5:36 PM


Views: 12483
Re: [FishMonger] CGI.pm radio button doesn't support "id" ?

tried to do that, but i only see radio_group(), not radio() ...

call it twice ?


In Reply To
You'll probably need to print each radio button individually.



(This post was edited by ningji on May 13, 2014, 5:38 PM)


FishMonger
Veteran / Moderator

May 13, 2014, 5:42 PM


Views: 12474
Re: [ningji] CGI.pm radio button doesn't support "id" ?

So, use 3 radio groups with a single item.


Code
#!/usr/bin/perl 

use strict;
use warnings;
use CGI qw(:standard);
use CGI::Pretty;

my %labels;

print header(),
start_html(),
radio_group(-name => 'group_name',
-values => 'eenie',
-default => '',
-labelattributes => { id => 'id1' }),
radio_group(-name => 'group_name',
-values => 'meenie',
-default => '',
-labelattributes => { id => 'id2' }),
radio_group(-name => 'group_name',
-values => 'minie',
-default => '',
-labelattributes => { id => 'id3' }),
end_html();



ningji
User

May 13, 2014, 5:44 PM


Views: 12472
Re: [FishMonger] CGI.pm radio button doesn't support "id" ?

got it, thanks so much !


In Reply To
So, use 3 radio groups with a single item.


Code
#!/usr/bin/perl 

use strict;
use warnings;
use CGI qw(:standard);
use CGI::Pretty;

my %labels;

print header(),
start_html(),
radio_group(-name => 'group_name',
-values => 'eenie',
-default => '',
-labelattributes => { id => 'id1' }),
radio_group(-name => 'group_name',
-values => 'meenie',
-default => '',
-labelattributes => { id => 'id2' }),
radio_group(-name => 'group_name',
-values => 'minie',
-default => '',
-labelattributes => { id => 'id3' }),
end_html();