Announcement Announcement Module
Collapse
No announcement yet.
javascript form validation: select box Page Title Module
Move Remove Collapse
Search Search Module
Collapse

Advertisement Advertisement Module
Collapse

Latest Topics Latest Topics Module
Collapse

  • Kayekaye
    Comment on Client charging/payment issues
    Kayekaye
    Yeah, nice huh? I probably would have done it for free if they had asked nicely and respected me. Another relative did hire me and my writing partner to produce a full id campaign and we delivered. When...
    Today, 04:04 AM
  • Kayekaye
    Comment on Book cover critique
    Kayekaye
    Yup, that's what I would do. It's a bit unbalanced. You can still have the veggies look free form, and ever make more of them on the bottom but it's just unbalanced to me. It doesn't have to be justified,...
    Today, 03:56 AM
  • KitchWitch
    Reply to Inquiry about Current Designers
    KitchWitch
    I think eventually every artist finds a style they either prefer or excel at. Unfortunately, in graphic design you are not designing to satisfy your own idea(s) of art and style. Graphic design solves...
    Today, 02:22 AM
  • KitchWitch
    Reply to Feedback on image compositing/photomedia piece
    KitchWitch
    Hi Courtney and welcome to GDF.

    We ask all new members to read very important links here and here. These explain the rules, how the forum runs and a few inside jokes. No, you haven't done...
    Today, 02:16 AM
  • pdodd72
    Feedback on image compositing/photomedia piece
    pdodd72
    Hi,

    I have created a photomedia design by compositing 5 photos I took into 1 image.

    I would appreciate any feedback you may have on it.

    Thanks
    Courtney...
    Today, 01:49 AM

X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • javascript form validation: select box

    i'm working with a registration form & paypal integration...

    the form is validated with javascript and uses an array of rules thusly:

    Code:
    rules.push("required,email,Please enter your email address.");
    but now i need to add a select box where the user can choose a date...i've figured out how to pass it thru to paypal; however, i'm stumped as to how to make this field required, making sure they select a date...

    is there a way?
    Monarchs Rule!

  • #2
    You should be doing this on the server side not the client side. All I need to do is turn off javascript to bypass everything you have set-up. Considering your dealing with money that doesn't seem very good.

    Comment


    • #3
      point taken ...

      i have a lengthy js file and several php files here, so i'm thinking it's been handled; although, there is a chance the programmer who wrote this app failed in his duties, but no evidence...
      Monarchs Rule!

      Comment


      • #4
        Oh… so your just writing something to check before the form has been submitted. Well that changes things. So wouldn't making sure they select a date be accomplished similar to the below:

        Code:
        rules.push("required,date,Please choose a date.");
        I'm assuming the second item in that list is either a name or id attribute of a input element – correct?

        To offer any detailed advice ethough I would need to know the library or see the functions your working with.

        Comment


        • #5
          here is my code for the select box:
          Code:
           <tr>
             <td>Workshop Date</td>
             <td>
            <select name="os0">
             <option value=""></option>
             <option value="June 22-26, 2009">June 22-26, 2009</option> 
             <option value="July 4_test">July 4_test</option>
            </select>
             </td>
           </tr>
          the name="os0" corresponds to the hidden input value i want to send to paypal, so i'm thinking i shouldn't change it...

          and, writing the rule.push with the name does work validation-wise; however, even if i select a date i get an alert...so i'm unsure what to do about that...
          Monarchs Rule!

          Comment


          • #6
            What does the js look like?

            Comment


            • #7
              umm...scary?! ...it's 689 lines

              here's my rule:

              Code:
              rules.push("required,os0,Please select the date you wish to attend.");
              Monarchs Rule!

              Comment


              • #8
                this looks like the most relevant bit:

                Code:
                    // now, validate whatever is required of the field
                    switch (requirement)
                    {
                      case "required":
                     
                        // if radio buttons or multiple checkboxes:
                        if (form[fieldName].type == undefined)
                        {
                          var oneIsChecked = false;
                          for (var j=0; j<form[fieldName].length; j++)
                          {
                            if (form[fieldName][j].checked)
                              oneIsChecked = true;
                          }
                          if (!oneIsChecked)
                          {
                            alertMessage(form[fieldName], errorMessage);
                            return false;           
                          }
                        }
                        else if (form[fieldName].type == "select-multiple")
                        {          
                          var oneIsSelected = false;
                          for (k=0; k<form[fieldName].length; k++)
                          {
                            if (form[fieldName][k].selected)
                              oneIsSelected = true;
                          }
                          // if no options have been selected, or if there ARE no options in the multi-select 
                          // dropdown, return false
                          if (!oneIsSelected || form[fieldName].length == 0)
                          {
                            alertMessage(form[fieldName], errorMessage);
                            return false;          
                          }
                        }
                but i'm not sure i should be messing with it...
                Monarchs Rule!

                Comment


                • #9
                  whelp...looks like a dropdown select box is out and radio buttons are in...it's not pretty, but it works...

                  thanks for your help and patience tZ!
                  Monarchs Rule!

                  Comment


                  • #10
                    The js is wrong.

                    Code:
                              for (k=0; k<form[fieldName].length; k++)
                              {
                                if (form[fieldName][k].selected.value && form[fieldName][k].selected.value!='')
                                  oneIsSelected = true;
                              }
                    I'm relatively certain that was the problem.

                    Comment


                    • #11
                      ahhh!...i'll have to experiment with that when i get a chance...thanks!
                      Monarchs Rule!

                      Comment

                      Mediabistro A division of Prometheus Global Media home | site map | advertising/sponsorships | careers | contact us | help courses | browse jobs | freelancers | content | member benefits | reprints & permissions terms of use | privacy policy Copyright © 2015 Mediabistro Inc.
                      Working...
                      X