views:

76

answers:

1
$selected = ' selected="selected"'
# or
$selected = qq( selected="selected")

is returned as:

selected="selected"

which is an invalid HTML attribute, ofcourse.

How do I fix it?

Edited to add:

<select name="alignment" class="select" 
    <%== param('feature') ? '' : 'disabled'; %>
>
% foreach (keys %al) {
%  my $selected = param('aligment') && param('aligment') eq $_ ? ' selected' : '';
%
%  if (!param('aligment') && $_ eq 'left') { $selected = ' selected' }
%
    <option value="<%=$_%>" <%= $selected %>>
     <%= $al{$_} %>
    </option>
%        
% }
</select>

Thanks!

+4  A: 

Hi,

according to Mojolicious web framework documents you would need to add and extra = at <%= in order to print it in raw format.

<%= $selected %>

would be

<%== $selected %>

for more reference you can read this http://github.com/kraih/mojo/blob/master/lib/Mojolicious/Guides/Rendering.pod

try like this:

<select name="alignment" class="select" 
    <%== param('feature') ? '' : 'disabled'; %>
>
% foreach (keys %al) {
%  my $selected = param('aligment') && param('aligment') eq $_ ? ' selected' : '';
%
%  if (!param('aligment') && $_ eq 'left') { $selected = ' selected' }
%
<option value="<%=$_%>"
 <%= $selected %>
>
     <%= $al{$_} %>
    </option>
%        
% }
</select>

or

<select name="alignment" class="select" 
    <%== param('feature') ? '' : 'disabled'; %>
>
% foreach (keys %al) {
%  my $selected = param('aligment') && param('aligment') eq $_ ? ' selected="selected"' : '';
%
%  if (!param('aligment') && $_ eq 'left') { $selected = ' selected="selected"' }
%
<option value="<%=$_%>"
 <%== $selected %>
>
     <%= $al{$_} %>
    </option>
%        
% }
</select>
Prix
Edited my question to include the relevant portion of the code.
Nimbuz
It seems youre using a module like Toolkit or so, can you post what is in the top of your code the "use CGI;" etc...
Prix
Yes, its based on Mojolicious web framework. Found no instances of "use CGI" in the whole code.
Nimbuz
Found the answer i belive, updated the post
Prix
Awesome!! :) Just one thing though, it doesn't print the ending '>' of the option tag, so its <option value="default" selected="selected" instead of <option value="default" selected="selected">
Nimbuz
try putting a space between >> to look like > > i am not experienced with this framework at all that was all the information i could find but it might be a bug perhaps ? finalizing the %> with an extra > might get read all together ...
Prix
I am wondering, inst there an option for the html option like you have for input ? <%= input 'test', type => 'text' %> so you would go like <%= option $_, selected => true %> or something alike, but since the documentation was very limited i would need to acutally look into the .pm files to figure it out ...
Prix
`$selected = ' selected=\"selected\"'`and then `<option value="<%=$_%>" <%== $selected %> >` doesn't seem to fix it. Hmm...
Nimbuz
you dont need to scape the " you are already using single quote also, it just run thru my mind the correct HTML code for a selected option in a dropdown is selected only and not selected="selected" ... Looking at your code posted above check your select, the ending > is on the next line instead of next to it, try doing it like that...
Prix
`"selected"` or `selected="selected"` (either is valid) but the problem is using either of those doesn't close the ending > of the the option tag. Tried putting the ending > on new line.
Nimbuz
updated the post try it like the update.
Prix
I started all over again and somehow its fixed. Strange, but good for me. :) BTW, if you're a perl expert and familiar with mojolicious framework and if you're interested in assisting me, professionally, with this (skinning a single-page tiny perl app), please let me know your email so we can talk. its nearly done but the last few things are taking hours cause I know nothing about perl. Thanks!
Nimbuz
i am sorry, my experience with mojolicious is near 0, first time i heard of it was when you mentioned it so i went to take a look at it to see how good it was... usually i do my own stuff from scratch using C::APP and H::Template and tune it to my needs. Glad you got it fixed.
Prix
I don't think you need to know mojolicious to skin the app, its mainly html with perl code in between, and the app itself is too simple small, just one-page (at the frontend). no?
Nimbuz
well you need to know all the rendering and the options you have available within it, and everything, from what i saw ... but if u have any questions you can drop a pm here with the link and i will try to help you what with what i can no problem ;)
Prix
There's no PM functionality on SO, can we talk on gTalk?
Nimbuz
i meant, if you send a PM in this Question i will get notified and if u reply with another question link, i will be able to check it and help you out with what i can :)
Prix
meant to say COMMENT my bad
Prix