hi sam

first off, javascript is not really fun, but here goes.

your form should have the same name as the formbean you associate with it.
you can check this in the html code generated from your jsp. the html:form
tag does not supply an attribute for setting/overriding the name of the form
(correct me if i'm wrong).

furthermore, if you don't want to use the document.forms[...] syntax, you
can use things like document.getElementsByName, document.getElementById etc.
You could even get all elements in the document, filter out the checkboxes
and modify/check attributes like that. you can find a nice explanation of
document.forms[] vs. document.getElementsByName when you google for
"selfhtml"

just make sure that you are working with a browser that gives you nice error
messages while debugging your javascript -> like mozilla.

andreas

-----Ursprungliche Nachricht-----
Von: as as [mailto:[EMAIL PROTECTED]
Gesendet: Mittwoch, 17. Marz 2004 19:27
An: Struts Users Mailing List
Betreff: RE: Single Checkbox Required


Hi,

Interesting...
"yourForm- where do we mention this in the struts's <html:form> tag....

Thanks!
Sam
(I had similar error where my form on submission would say ".length " is
null...was probably not able to invoke checkbox.length on the form already
as struts form is generated only after hitting the server but we may need
javascript validation much before that-on client side...
please...correct me if i am wrong.

Thanks


my code snipet below:


<html:form action="edit" name="displayForm" type="com.model.DisplayForm" >

<table border="0" width="100%">

<input type=checkbox name="edit_all" value="Check All"
onClick="check(this.form.list)"></th>

......

...

<logic:iterate id="driver" name="drivers">

<input type=checkbox value="list" name="delete_<bean:write name="book"
property="ISBN" />">



...

...

<SCRIPT LANGUAGE="JavaScript">

var checkflag = "false";

function check(field) {

if (checkflag == "false") {

for (i = 0; i < field.length; i++) {

field[i].checked = true;}

checkflag = "true";

return "Uncheck All"; }

else {

for (i = 0; i < field.length; i++) {

field[i].checked = false; }

checkflag = "false";

return "Check All"; }

}



Brendan Richards <[EMAIL PROTECTED]> wrote:
Sorry - didn't realise you were using javascript validation (should have
read your post more carefully).

You could add your own client side code:


        function checkTheBox() {
                if (!document.forms['yourForm'].myCheckbox.checked) {
                        alert("you must check the box to proceed");
                        return false;
                } else {
                        return true;
                }
        }









-----Original Message-----
From: Morowitz, Michael [mailto:[EMAIL PROTECTED]
Sent: 17 March 2004 17:14
To: Struts Users Mailing List
Subject: RE: Single Checkbox Required

But, when I mark it "required" in my validator.xml, it doesn't work.
The javascript that is generated (validateRequired) does not apply to
fields of type "checkbox". I suppose I could modify the javascript, but
I want both server side and client-side validation.

-M
-----Original Message-----
From: Brendan Richards [mailto:[EMAIL PROTECTED]
Sent: Wednesday, March 17, 2004 10:52 AM
To: Struts Users Mailing List
Subject: RE: Single Checkbox Required


What makes a checkbox unusual is that it only submits a value when
checked - when unchecked nothing is submitted. You should therefore be
able to validate that it's been checked with a standard "required"
validator.




-----Original Message-----
From: Morowitz, Michael [mailto:[EMAIL PROTECTED]
Sent: 17 March 2004 16:26
To: [EMAIL PROTECTED]
Subject: Single Checkbox Required

I have searched the archive of the list and I came up empty.

I want to use validator.xml to indicate that a single checkbox must be
checked 'true' on my form. Has anyone had success simply indicating a
boolean field to be "required"?

I've noticed that in the client-side javascript that is generated,
validateRequired does not look at fields of type 'checkbox'.

I have read that commons-validator added this functionality at some
point in the past, but has it not made it into the Struts validtion
package?

Thanks,
Michael

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Do you Yahoo!?
Yahoo! Mail - More reliable, more storage, less spam


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to