Mailing List Archive

Can't init checkbox
Hi,

I'm not able to init checkbox

<form>
[- $fdat{xxx} = "on" -]
<input name=xxx type=checkbox>
</form>

No matter what I put in $fdat{xxx} (on,true,checked,1 etc), checkbox is
never checked. All other elements like text's, select's, radio's work as
expected. What's going on? (I'm running with option=8208, embperl is
1.2.1)

- Robert
Re: Can't init checkbox [ In reply to ]
First, name contains the field name of the form element, what you need
to set is the value attribute.

Second, the value should be "CHECKED" not on.

Robert wrote:
>
> Hi,
>
> I'm not able to init checkbox
>
> <form>
> [- $fdat{xxx} = "on" -]
> <input name=xxx type=checkbox>
> </form>
>
> No matter what I put in $fdat{xxx} (on,true,checked,1 etc), checkbox is
> never checked. All other elements like text's, select's, radio's work as
> expected. What's going on? (I'm running with option=8208, embperl is
> 1.2.1)
>
> - Robert
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> For additional commands, e-mail: embperl-help@perl.apache.org

--
__________________________________________________________
Mr. Erich L. Markert emarkert@pace.edu
Computer Learning Center TEL (914)422-4328
Pace University
1 Martine Ave
White Plains, New York 10606-1932

Those who do not understand Unix are condemned to reinvent it, poorly.
-- Henry Spencer
Re: Can't init checkbox [ In reply to ]
"Erich L. Markert" wrote:
>
> First, name contains the field name of the form element, what you need
> to set is the value attribute.

I'm afraid I don't undestand what you're saying. [- $fdat{xxx} = ... -]
used to init form element named xxx last time I looked in the docs.

> Second, the value should be "CHECKED" not on.

Yes I tried [- $fdat{xxx} = "checked" -], doesn't work either.

- Robert



> Robert wrote:
> >
> > Hi,
> >
> > I'm not able to init checkbox
> >
> > <form>
> > [- $fdat{xxx} = "on" -]
> > <input name=xxx type=checkbox>
> > </form>
> >
> > No matter what I put in $fdat{xxx} (on,true,checked,1 etc), checkbox is
> > never checked. All other elements like text's, select's, radio's work as
> > expected. What's going on? (I'm running with option=8208, embperl is
> > 1.2.1)
> >
> > - Robert
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> > For additional commands, e-mail: embperl-help@perl.apache.org
>
> --
> __________________________________________________________
> Mr. Erich L. Markert emarkert@pace.edu
> Computer Learning Center TEL (914)422-4328
> Pace University
> 1 Martine Ave
> White Plains, New York 10606-1932
>
> Those who do not understand Unix are condemned to reinvent it, poorly.
> -- Henry Spencer
Re: Can't init checkbox [ In reply to ]
This will work.

<INPUT TYPE="checkbox" NAME="some_field_name" VALUE="true" [$ if defined $fdat{'some_field_name'} $] CHECKED [$ endif $]>

Also, a really good online HTML reference can be found at:

http://www.zdnet.com/devhead/resources/tag_library/

Robert wrote:
>
> "Erich L. Markert" wrote:
> >
> > First, name contains the field name of the form element, what you need
> > to set is the value attribute.
>
> I'm afraid I don't undestand what you're saying. [- $fdat{xxx} = ... -]
> used to init form element named xxx last time I looked in the docs.
>
> > Second, the value should be "CHECKED" not on.
>
> Yes I tried [- $fdat{xxx} = "checked" -], doesn't work either.
>
> - Robert
>
> > Robert wrote:
> > >
> > > Hi,
> > >
> > > I'm not able to init checkbox
> > >
> > > <form>
> > > [- $fdat{xxx} = "on" -]
> > > <input name=xxx type=checkbox>
> > > </form>
> > >
> > > No matter what I put in $fdat{xxx} (on,true,checked,1 etc), checkbox is
> > > never checked. All other elements like text's, select's, radio's work as
> > > expected. What's going on? (I'm running with option=8208, embperl is
> > > 1.2.1)
> > >
> > > - Robert
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> > > For additional commands, e-mail: embperl-help@perl.apache.org
> >
> > --
> > __________________________________________________________
> > Mr. Erich L. Markert emarkert@pace.edu
> > Computer Learning Center TEL (914)422-4328
> > Pace University
> > 1 Martine Ave
> > White Plains, New York 10606-1932
> >
> > Those who do not understand Unix are condemned to reinvent it, poorly.
> > -- Henry Spencer

--
__________________________________________________________
Mr. Erich L. Markert emarkert@pace.edu
Computer Learning Center TEL (914)422-4328
Pace University
1 Martine Ave
White Plains, New York 10606-1932

Those who do not understand Unix are condemned to reinvent it, poorly.
-- Henry Spencer
RE: Can't init checkbox [ In reply to ]
>
> I'm not able to init checkbox
>
> <form>
> [- $fdat{xxx} = "on" -]
> <input name=xxx type=checkbox>
> </form>
>

<input name=xxx type=checkbox value=on>

You need the value attribut. Embperl add the checked attribute when the
value in %fdat is the same as that one given in the value attribute of the
tag and will remove it if the values are different.

The example that Erich wrote works too, but is more complex

Gerald




-------------------------------------------------------------
Gerald Richter ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post: Tulpenstrasse 5 D-55276 Dienheim b. Mainz
E-Mail: richter@ecos.de Voice: +49 6133 925151
WWW: http://www.ecos.de Fax: +49 6133 925152
-------------------------------------------------------------
Re: Can't init checkbox [ In reply to ]
Thanks everybody who answered. Brief resume: I used to write

<input name=xxx type=text value=[+ $fdat{xxx} +]>

while now I prefer cleaner way using Embperl's feature of automatic form
fields initialization

[- $fdat{xxx} = "stuf" -]
... a lot of HTML ...
<input name=xxx type=text>

This works fine (at least) for text fields and selects, but it fails
badly for checkboxes, where one has to write something like

[- $fdat{xxx} = "some value" -]
... a lot of HTML
<input name=xxx type=checkbox value="some value">

and Embperl adds boolean attribute 'checked' when needed.

I think it would be more intuitive if Embperl allowed for some default
value, so one could write

[- $fdat{xxx} = "some value" -]
<input name=xxx type=checkbox>

and Embperl would understand that "some value" is perlish true/false and
added 'checked' accordingly.
At least it confused me enough so I spent most of this afternoon fooling
around with all options I could think of and even reinstaling Embperl
;-(.

- Robert
RE: Can't init checkbox [ In reply to ]
>
> I think it would be more intuitive if Embperl allowed for some default
> value, so one could write
>
> [- $fdat{xxx} = "some value" -]
> <input name=xxx type=checkbox>
>
> and Embperl would understand that "some value" is perlish true/false and
> added 'checked' accordingly.

The problem is that you could have multiple checkboxes (or more common
radiobuttons) with the same name:

<input name=xxx type=checkbox value=a>
<input name=xxx type=checkbox value=b>
<input name=xxx type=checkbox value=c>

How should Embperl decide what to do here? I think the current way is
correct, but I add a note to the docs/faq

Gerald


-------------------------------------------------------------
Gerald Richter ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post: Tulpenstrasse 5 D-55276 Dienheim b. Mainz
E-Mail: richter@ecos.de Voice: +49 6133 925151
WWW: http://www.ecos.de Fax: +49 6133 925152
-------------------------------------------------------------