[Javascript] Re: Javascript digest, Vol 1 #401 - 3 msgs

Teresa L Cannon Teresa.Cannon at ipaper.com
Wed Sep 19 13:48:18 CDT 2001


Rodney, thanks for your analysis.  To response to the comment regarding:  "
I have to say I have not got into the logic of what you are doing here. But
it does seem to have come off the rails a bit when you found you needed
unique names."

This application that I am developing is a Web Survey Creation" site,
created dynamically with 4 answer types to choose from for each question:
checkbox, radio buttons, text input & text area boxes.

One of the features that has been asked for is for the survey taker to be
able to "Save As Incomplete", to be submitted at a later date.

I have had to give the checkbox answer types a different name so when the
array goes in to see the results in the "Survey_Results" table, it compares
to the "Survey_Answer" table and if there are matches based upon QNumber &
ANumber, it goes into the CHECKED logic when displaying the survey,
otherwise it just displays the answers after the question.  To get it to
loop through the answers, the names need to be unique for checkbox objects
because they are the only ones that can have more than one answer.

Does this make sense now?  I am very open to any other way to do this.  If
it were a static page, this, of course, would be a piece of cake!

I could show you the ASP code, but this is a javascript forum.





                                                                                                                         
                    javascript-request@                                                                                  
                    LaTech.edu                To:     javascript at LaTech.edu                                              
                    Sent by:                  cc:                                                                        
                    javascript-admin at La       Subject:     Javascript digest, Vol 1 #401 - 3 msgs                        
                    Tech.edu                                                                                             
                                                                                                                         
                                                                                                                         
                    09/19/2001 12:02 PM                                                                                  
                    Please respond to                                                                                    
                    javascript                                                                                           
                                                                                                                         
                                                                                                                         




Send Javascript mailing list submissions to
     javascript at LaTech.edu

To subscribe or unsubscribe via the World Wide Web, visit
     http://www.LaTech.edu/mailman/listinfo/javascript
or, via email, send a message with subject or body 'help' to
     javascript-request at LaTech.edu

You can reach the person managing the list at
     javascript-admin at LaTech.edu

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Javascript digest..."


Today's Topics:

   1. Form Validation (Teresa L Cannon)
   2. Re: Form Validation (Rodney Myers)
   3. ADMIN: Unsubscribe, changing settings reminder. (David Merchant)

--__--__--

Message: 1
To: javascript at LaTech.edu
From: "Teresa L Cannon" <Teresa.Cannon at ipaper.com>
Date: Tue, 18 Sep 2001 14:36:29 -0500
Subject: [Javascript] Form Validation
Reply-To: javascript at LaTech.edu


I have a survey where I allow the users to "Save As Incomplete".  This
pulls out current information on questions they have answered and allows
them to go back and delete/update/insert answers before the final submit.
In order to do this, I have to give the check box elements a different
"name" because they can submit muliple answers for these types of
questions.  I have the following script to check to see if at least one
element (answer) is checked for each question.  I also have hidden elements
for my ASP page.

I am currently getting "Please check one of boxes in the next question"
because the checkbox names are different (and need to be).

Here's the HTML:

<HTML>
<HEAD>
<link rel="stylesheet" type="text/css" href="EHS.css">
<script language="JAVASCRIPT">
function GoForm2(form)
{
     if (document.Form2.finished[1].checked)
     {
          for (var e = 0; e < form.elements.length; e++)
          {
               var el = form.elements[e];
               if (el.type == 'radio' && el.type != 'hidden')
          {
          var group = form[el.name];
          var checked = false;
          if (!group.length)
               checked = el.checked;
          else
          for (var r = 0; r < group.length; r++)
               if ((checked = group[r].checked))
                    break;
               if (!checked)
               {
                    alert('Please check one of the radio buttons on the
next question.');
                    el.focus();
                    return false;
               }
          }
          else if (el.type == 'checkbox' && el.type != 'hidden')
          {
               var group = form[el.name];
               if (!group.length)
                    checked = el.checked;
               else
                    for (var r = 0; r < group.length; r++)
                         if ((checked = group[r].checked))
                              break;
                         if (!checked)
                         {
                              alert('Please check one of the checkboxes on
the next question.');
                              el.focus();
                              return false;
                         }
                    }
               else
               {
                    if (el.value == "" || el.value == null || el.value == "
" && el.type != 'hidden')
                    {
                         alert('Please answer the next question.');
                         el.focus();
                         return false;
                    }
               }
          }
          return true;
     }
     return true;
}
</script>
</HEAD>
<body bgcolor="#F0F0DF" leftmargin="0" topmargin="10">
<form action="Survey-Script.asp" name="Form2" id="Form2" method="post"
onsubmit="return GoForm2(this)">
<BR>
<TABLE align=center border="0" cellPadding="6" bgcolor=#E6E5DC cellSpacing
="1" width="70%">
     <TR bgColor=#E6E5DC bordercolor=#E6E5DC><TD colspan="2"></TD></TR>
     <TR bgColor=#E6E5DC>
          <TD align="right">1.&nbsp;&nbsp;</TD>
          <TD>Check all that you are responsible for below.</TD>
     </TR>
          <input type="hidden" Name="QNumber1" value="1">
          <input type="hidden" Name="Q1ACounter" value="4">
          <input type="hidden" Name="QType1" value="1">
     <TR bgColor=#E6E5DC><TD>&nbsp;</TD>
          <TD><input type="checkbox" Name="Q1A1" value="Erogonomics
Training" CHECKED>&nbsp;Erogonomics Training
               <input type="hidden" Name="Q1A1B" value="Erogonomics
Training"></TD>
     </TR>
     <TR bgColor=#E6E5DC><TD>&nbsp;</TD>
          <TD><input type="checkbox" Name="Q1A2" value="Health Issues"
CHECKED>&nbsp;Health Issues
               <input type="hidden" Name="Q1A2B" value="Health
Issues"></TD>
     </TR>
     <TR bgColor=#E6E5DC><TD>&nbsp;</TD>
          <TD><input type="checkbox" Name="Q1A3" value="Plant Safety">
&nbsp;Plant Safety<input type="hidden" Name="Q1A3B"></TD>
     </TR>
     <TR bgColor=#E6E5DC><TD>&nbsp;</TD>
          <TD><input type="checkbox" Name="Q1A4" value="Wastwater
Protocols">&nbsp;Wastwater Protocols
               <input type="hidden" Name="Q1A4B"></TD>
     </TR>
     <TR bgColor=#E6E5DC bordercolor=#E6E5DC><TD colspan="2"></TD></TR>
     <TR bgColor=#E6E5DC><TD align="right">2.&nbsp;&nbsp;</TD>
          <TD>Q2 is second?</TD>
     </TR>
          <input type="hidden" Name="QNumber2" value="2">
          <input type="hidden" Name="Q2ACounter" value="3">
          <input type="hidden" Name="QType2" value="1">
     <TR bgColor=#E6E5DC><TD>&nbsp;</TD>
          <TD><input type="checkbox" Name="Q2A1" value="1">&nbsp;1
               <input type="hidden" Name="Q2A1B"></TD>
     </TR>
     <TR bgColor=#E6E5DC><TD>&nbsp;</TD>
          <TD><input type="checkbox" Name="Q2A2" value="2" CHECKED>&nbsp;2
               <input type="hidden" Name="Q2A2B" value="2"></TD>
     </TR>
     <TR bgColor=#E6E5DC><TD>&nbsp;</TD>
          <TD><input type="checkbox" Name="Q2A3" value="3">&nbsp;3
               <input type="hidden" Name="Q2A3B"></TD>
     </TR>
     <TR bgColor=#E6E5DC bordercolor=#E6E5DC><TD colspan="2"></TD>
     </TR>
     <TR bgColor=#E6E5DC><TD align="right">3.&nbsp;&nbsp;</TD>
          <TD>Question three OK?</TD>
     </TR>
          <input type="hidden" Name="QNumber3" value="3">
          <input type="hidden" Name="Q3ACounter" value="2">
          <input type="hidden" Name="QType3" value="1">
     <TR bgColor=#E6E5DC><TD>&nbsp;</TD>
          <TD><input type="checkbox" Name="Q3A1" value="1">&nbsp;1
               <input type="hidden" Name="Q3A1B"></TD>
     </TR>
     <TR bgColor=#E6E5DC><TD>&nbsp;</TD>
          <TD><input type="checkbox" Name="Q3A2" value="2">&nbsp;2
               <input type="hidden" Name="Q3A2B"></TD>
     </TR>
     <TR bgColor=#E6E5DC bordercolor=#E6E5DC><TD colspan="2"></TD>
     </TR>
     <TR bgcolor="C0C0C0">
          <input type="hidden" name="Survey" value="266">
          <input type="hidden" name="LID" value="322111">
          <input type="hidden" name="Count" value="3">
          <input type="hidden" name="R" value="4">
          <TD align="right"><BR>
               <INPUT type="radio" name="finished" value="N">&nbsp;Save as
Incomplete
          </TD>
          <TD align="left"><BR>
               <INPUT type="radio" name="finished" value="Y" checked>
&nbsp;Submit Final Survey
          </TD>
     </TR>
     <TR bgcolor="C0C0C0">
          <TD colspan="2" align="center">
               <input TYPE="submit" VALUE="Save/Submit Survey" Name
="button1"><BR>
          </TD>
     </TR>
</TABLE>
</form>
</body>
</HTML>

It is still giving me an alert. How do I get around this?



--__--__--

Message: 2
Date: Tue, 18 Sep 2001 22:55:55 +0100
From: Rodney Myers <rodney at aflyingstart.net>
Organization: Hodgson Myers Associates Ltd / Shop at ssistant eCommerce
Solutions
To: javascript at LaTech.edu
Subject: Re: [Javascript] Form Validation
Reply-To: javascript at LaTech.edu

Teresa,

Interesting.

Excuse the critique, but when I look at scripts I make notes. so you may as
well have them:


function GoForm2(form)
So form object is defined  in parameter

So why?
     if (document.Form2.finished[1].checked)
and not
     if (form.finished[1].checked)

 for (var e = 0; e < form.elements.length; e++)
This goes right through the form - including the radio buttons at the end
which
switch the type of submit, the four hidden fields near the ned and the
Submit
button

Could be
 for (var e = 0; e < form.elements.length-7; e++)

var el = form.elements[e];
if (el.type == 'radio' && el.type != 'hidden')
 {
   var group = form[el.name];

This last line flummoxes me? I could understand it if you had sets of
elements
with the same name but you (now?) have not (but once did?)

Elements : 34
[##] Type            Name                Value
[ 0] hidden          QNumber1            1
[ 1] hidden          Q1ACounter          4
[ 2] hidden          QType1              1
[ 3] checkbox        Q1A1                CHECKED              value =
Erogonomics Training
[ 4] hidden          Q1A1B               Erogonomics Training
[ 5] checkbox        Q1A2                CHECKED              value =
Health
Issues
[ 6] hidden          Q1A2B               Health Issues
[ 7] checkbox        Q1A3                 -OFF-               value = Plant
Safety
[ 8] hidden          Q1A3B
[ 9] checkbox        Q1A4                 -OFF-               value =
Wastwater
Protocols
[10] hidden          Q1A4B
[11] hidden          QNumber2            2
[12] hidden          Q2ACounter          3
[13] hidden          QType2              1
[14] checkbox        Q2A1                 -OFF-               value = 1
[15] hidden          Q2A1B
[16] checkbox        Q2A2                CHECKED              value = 2
[17] hidden          Q2A2B               2
[18] checkbox        Q2A3                 -OFF-               value = 3
[19] hidden          Q2A3B
[20] hidden          QNumber3            3
[21] hidden          Q3ACounter          2
[22] hidden          QType3              1
[23] checkbox        Q3A1                 -OFF-               value = 1
[24] hidden          Q3A1B
[25] checkbox        Q3A2                 -OFF-               value = 2
[26] hidden          Q3A2B
[27] hidden          Survey              266
[28] hidden          LID                 322111
[29] hidden          Count               3
[30] hidden          R                   4
[31] radio           finished             -OFF-               value = N
[32] radio           finished            CHECKED              value = Y
[33] submit          button1             SUBMIT : Save/Submit Survey

I think you would need to make artificial groups searching for prefixes in
names such as "Q1"

I have to say I have not got into the logic of what you are doing here. But
it
does seem to have come off the rails a bit when you found you needed unique
names.

Doable, certainly, but now I must do my own work<g>

hth

Rodney

Teresa L Cannon wrote:

> I have a survey where I allow the users to "Save As Incomplete".  This
> pulls out current information on questions they have answered and allows
> them to go back and delete/update/insert answers before the final submit.
> In order to do this, I have to give the check box elements a different
> "name" because they can submit muliple answers for these types of
> questions.  I have the following script to check to see if at least one
> element (answer) is checked for each question.  I also have hidden
elements
> for my ASP page.
>
> I am currently getting "Please check one of boxes in the next question"
> because the checkbox names are different (and need to be).
>
> Here's the HTML:
>
> <HTML>
> <HEAD>
> <link rel="stylesheet" type="text/css" href="EHS.css">
> <script language="JAVASCRIPT">
> function GoForm2(form)
> {
>      if (document.Form2.finished[1].checked)
>      {
>           for (var e = 0; e < form.elements.length; e++)
>           {
>                var el = form.elements[e];
>                if (el.type == 'radio' && el.type != 'hidden')
>           {
>           var group = form[el.name];
>           var checked = false;
>           if (!group.length)
>                checked = el.checked;
>           else
>           for (var r = 0; r < group.length; r++)
>                if ((checked = group[r].checked))
>                     break;
>                if (!checked)
>                {
>                     alert('Please check one of the radio buttons on the
> next question.');
>                     el.focus();
>                     return false;
>                }
>           }
>           else if (el.type == 'checkbox' && el.type != 'hidden')
>           {
>                var group = form[el.name];
>                if (!group.length)
>                     checked = el.checked;
>                else
>                     for (var r = 0; r < group.length; r++)
>                          if ((checked = group[r].checked))
>                               break;
>                          if (!checked)
>                          {
>                               alert('Please check one of the checkboxes
on
> the next question.');
>                               el.focus();
>                               return false;
>                          }
>                     }
>                else
>                {
>                     if (el.value == "" || el.value == null || el.value
== "
> " && el.type != 'hidden')
>                     {
>                          alert('Please answer the next question.');
>                          el.focus();
>                          return false;
>                     }
>                }
>           }
>           return true;
>      }
>      return true;
> }
> </script>
> </HEAD>
> <body bgcolor="#F0F0DF" leftmargin="0" topmargin="10">
> <form action="Survey-Script.asp" name="Form2" id="Form2" method="post"
> onsubmit="return GoForm2(this)">
> <BR>
> <TABLE align=center border="0" cellPadding="6" bgcolor=#E6E5DC
cellSpacing
> ="1" width="70%">
>      <TR bgColor=#E6E5DC bordercolor=#E6E5DC><TD colspan="2"></TD></TR>
>      <TR bgColor=#E6E5DC>
>           <TD align="right">1.&nbsp;&nbsp;</TD>
>           <TD>Check all that you are responsible for below.</TD>
>      </TR>
>           <input type="hidden" Name="QNumber1" value="1">
>           <input type="hidden" Name="Q1ACounter" value="4">
>           <input type="hidden" Name="QType1" value="1">
>      <TR bgColor=#E6E5DC><TD>&nbsp;</TD>
>           <TD><input type="checkbox" Name="Q1A1" value="Erogonomics
> Training" CHECKED>&nbsp;Erogonomics Training
>                <input type="hidden" Name="Q1A1B" value="Erogonomics
> Training"></TD>
>      </TR>
>      <TR bgColor=#E6E5DC><TD>&nbsp;</TD>
>           <TD><input type="checkbox" Name="Q1A2" value="Health Issues"
> CHECKED>&nbsp;Health Issues
>                <input type="hidden" Name="Q1A2B" value="Health
> Issues"></TD>
>      </TR>
>      <TR bgColor=#E6E5DC><TD>&nbsp;</TD>
>           <TD><input type="checkbox" Name="Q1A3" value="Plant Safety">
> &nbsp;Plant Safety<input type="hidden" Name="Q1A3B"></TD>
>      </TR>
>      <TR bgColor=#E6E5DC><TD>&nbsp;</TD>
>           <TD><input type="checkbox" Name="Q1A4" value="Wastwater
> Protocols">&nbsp;Wastwater Protocols
>                <input type="hidden" Name="Q1A4B"></TD>
>      </TR>
>      <TR bgColor=#E6E5DC bordercolor=#E6E5DC><TD colspan="2"></TD></TR>
>      <TR bgColor=#E6E5DC><TD align="right">2.&nbsp;&nbsp;</TD>
>           <TD>Q2 is second?</TD>
>      </TR>
>           <input type="hidden" Name="QNumber2" value="2">
>           <input type="hidden" Name="Q2ACounter" value="3">
>           <input type="hidden" Name="QType2" value="1">
>      <TR bgColor=#E6E5DC><TD>&nbsp;</TD>
>           <TD><input type="checkbox" Name="Q2A1" value="1">&nbsp;1
>                <input type="hidden" Name="Q2A1B"></TD>
>      </TR>
>      <TR bgColor=#E6E5DC><TD>&nbsp;</TD>
>           <TD><input type="checkbox" Name="Q2A2" value="2" CHECKED>
&nbsp;2
>                <input type="hidden" Name="Q2A2B" value="2"></TD>
>      </TR>
>      <TR bgColor=#E6E5DC><TD>&nbsp;</TD>
>           <TD><input type="checkbox" Name="Q2A3" value="3">&nbsp;3
>                <input type="hidden" Name="Q2A3B"></TD>
>      </TR>
>      <TR bgColor=#E6E5DC bordercolor=#E6E5DC><TD colspan="2"></TD>
>      </TR>
>      <TR bgColor=#E6E5DC><TD align="right">3.&nbsp;&nbsp;</TD>
>           <TD>Question three OK?</TD>
>      </TR>
>           <input type="hidden" Name="QNumber3" value="3">
>           <input type="hidden" Name="Q3ACounter" value="2">
>           <input type="hidden" Name="QType3" value="1">
>      <TR bgColor=#E6E5DC><TD>&nbsp;</TD>
>           <TD><input type="checkbox" Name="Q3A1" value="1">&nbsp;1
>                <input type="hidden" Name="Q3A1B"></TD>
>      </TR>
>      <TR bgColor=#E6E5DC><TD>&nbsp;</TD>
>           <TD><input type="checkbox" Name="Q3A2" value="2">&nbsp;2
>                <input type="hidden" Name="Q3A2B"></TD>
>      </TR>
>      <TR bgColor=#E6E5DC bordercolor=#E6E5DC><TD colspan="2"></TD>
>      </TR>
>      <TR bgcolor="C0C0C0">
>           <input type="hidden" name="Survey" value="266">
>           <input type="hidden" name="LID" value="322111">
>           <input type="hidden" name="Count" value="3">
>           <input type="hidden" name="R" value="4">
>           <TD align="right"><BR>
>                <INPUT type="radio" name="finished" value="N">&nbsp;Save
as
> Incomplete
>           </TD>
>           <TD align="left"><BR>
>                <INPUT type="radio" name="finished" value="Y" checked>
> &nbsp;Submit Final Survey
>           </TD>
>      </TR>
>      <TR bgcolor="C0C0C0">
>           <TD colspan="2" align="center">
>                <input TYPE="submit" VALUE="Save/Submit Survey" Name
> ="button1"><BR>
>           </TD>
>      </TR>
> </TABLE>
> </form>
> </body>
> </HTML>
>
> It is still giving me an alert. How do I get around this?
>

--
Shop at ssistant Add-ons and Developer Workshops
http://www.aflyingstart.net/addons/

Enquiries regarding Shop at ssistant Classic training :
Call 01256 880770

Rodney Myers
Based in Oxford, England
Technical Director, Shop at ssistant eCommerce Solutions



--__--__--

Message: 3
Date: Wed, 19 Sep 2001 09:57:37 -0500
To: javascript at LaTech.edu
From: David Merchant <merchant at LATECH.EDU>
Subject: [Javascript] ADMIN: Unsubscribe, changing settings reminder.
Reply-To: javascript at LaTech.edu

To unsubscribe or to change your membership settings (nomail, digest, etc),
go to the URL listed at the end of each JavaScript posting:


>_____________________________________________
>Javascript mailing list
>Javascript at LaTech.edu
>http://www.LaTech.edu/mailman/listinfo/javascript

If you need your membership password, at the bottom of the page
http://www.LaTech.edu/mailman/listinfo/javascript, there will be a box
where you can enter your email address, when you hit the submit button you
will be taken to a page where you can have your list membership password
emailed to you if you have forgotten it or misplaced the monthly password
reminder the Mailman program sends out.  Once you have the password, you
can then change your membership settings.

If you still experience troubles, then send me an email and I can manually
change your settings or unsubscribe you.  Because I have a day job, please
be advised that it may take a day or two for me to manually change your
settings.

TTFN,
David

Head, Systems Dept, Louisiana Tech University
merchant at latech.edu
JavaScript List Administrator (www.mountaindragon.com/javascript/)
Webmaster, HTML Encyclopedia (www.mountaindragon.com/html/)
Webmaster, Memorial Day Page: (www.usmemorialday.org/)



--__--__--

_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
http://www.LaTech.edu/mailman/listinfo/javascript


End of Javascript Digest






More information about the Javascript mailing list