Web Analytics Made Easy -
StatCounter Help with a form. - CodingForum

Announcement

Collapse
No announcement yet.

Help with a form.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with a form.

    I am not very experienced with Java Script, I need to build a form, there is one area I am not sure how to do. I am hoping someone here has had a similar problem and over come it.


    The portion I am trying to do consists of a array of 10 text boxes where the user is required to enter data into one of them.

    Has anyone ever done something similar to this?

    Thank you in advance

    Lance


    CODE:
    see attached...
    Attached Files

  • #2
    are you just looking to validate one of those form fields?? So you have ten but only one is required.
    I would rather be a lion for a day than a lamb that lives forever.

    Comment


    • #3
      Well out of ten one is required. Therefore, I need to validate as little as one but as many as 10 fields.

      It needs to be dynamic.

      Thanks
      Lance

      Comment


      • #4
        What is the validation criteria? YOu could just loop trhough the text boxes, check to see if they have stuff in them and if so validate them. Show us your code3 so far and tell us what the criteria for valifdation is.

        Comment


        • #5
          The criteria for validation is one of the text boxes is not Null. It is very simple, I just have never done anything other then validate one cell at a time.

          For example I usually check boxes like so:

          function CheckFields()
          {

          if (theForm.sr.value=="")
          {
          alert("Please enter the service request");
          document.theForm. sr.focus();
          return false;
          }

          if (theForm.web.value=="")
          {
          alert("Please if you found it form the web");
          document.theForm. web.focus();
          return false;
          }
          The problem with this is I do not care to check the other fields if at least one is checked.

          Thanks

          Comment


          • #6
            Show us the code for your form so we can see how it is set up.

            Comment


            • #7
              You could try something like this:

              Code:
              function CheckFields(){
                var controls=document.theForm.elements;
                var x = 10;
                for (i=0;i<controls.length;i++){ 
                  if(controls[i].type=="text"){
                     if(controls[i].value==""){
                        x-=1;}}}
                if(x==0){
                  alert("At least one text box must be filled.");
                  return false;}}
              USA

              Comment


              • #8
                ladon11's will work as long as the text boxes in questions are the only text boxes in your form which is why I want to see the code for your form.

                Comment


                • #9
                  I have attacehd the entire code along with the Javascript that I have already written.

                  THank you for your time
                  Attached Files

                  Comment


                  • #10
                    does anyone have an idea on how to do this?

                    Thanks
                    Lance

                    Comment


                    • #11
                      Which of the text fileds from your form will be validated in this manner?

                      Comment


                      • #12
                        The out of following fields at least one is required:

                        <tr>
                        <TD nowrap vAlign=top align=right width="30%"><font size="2" face="Arial, Helvetica, sans-serif"><b>Source</b></font><font face="Times New Roman, Times, serif" size="2" color="#990000">*</font></b></td>
                        </tr>
                        <tr>
                        <TD nowrap vAlign=top align=right width="30%"></td>
                        <td><font face="Arial" size="1">Service Request:</font>&nbsp;<input name="frmrequest" type=TEXT size='20%' value="" maxlength="20"></td>
                        </tr>
                        <tr>
                        <TD nowrap vAlign=top align=right width="30%"></td>
                        <td><font face="Arial" size="1">Web Site:</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="frmweb" type=TEXT size='20%' value="" maxlength="20"></td>
                        </tr>
                        <tr>
                        <TD nowrap vAlign=top align=right width="30%"></td>
                        <td><font face="Arial" size="1">Book/Manual:</font>&nbsp;&nbsp;&nbsp;&nbsp;<input name="frmbook" type=TEXT size='20%' value="" maxlength="20"></td>
                        </tr>
                        <tr>
                        <TD nowrap vAlign=top align=right width="30%"></td>
                        <td><font face="Arial" size="1">White Paper:</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="frmpaper" type=TEXT size='20%' value="" maxlength="20"></td>
                        </tr>
                        <tr>
                        <TD nowrap vAlign=top align=right width="30%"></td>
                        <td><font face="Arial" size="1">Other:</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="frmother" type=TEXT size='20%' value="" maxlength="20"></td>
                        </tr>


                        Thanks in advance for your help
                        Lance

                        Comment


                        • #13
                          I'm not sure I get this, but, anyway...

                          <script type="text/javascript" language="javascript">

                          function checkfields(f) {
                          var currEl, e = 0;
                          while (currEl = f.elements[e++])
                          if (currEl.oneRequired && currEl.value) return true;
                          alert('Something...');
                          return false;
                          }

                          </script>

                          HTML:

                          <form method="post" name="theForm" action="javascript&#58;alert('Submitted !')"
                          onsubmit="frmrequest.oneRequired=true;frmweb.oneRequired=true;
                          frmbook.oneRequired=true;frmpaper.oneRequired=true;
                          frmother.oneRequired=true;return checkfields(this)">

                          Just add the .oneRequired property (=true) for every field you want included in the group. The alerts can be customized, but it's hard to do so without some idea of the methodology behind all this. hth

                          Comment


                          • #14
                            I wanted to thank eveyone who helped me out with this problem.

                            Lance

                            Comment

                            Working...
                            X