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

Featured Images Featured Images Module
Collapse

Mediabistro Creative Sites Mediabistro Creative Sites Module
Collapse
Latest Topics Latest Topics Module
Collapse

  • damonharris
    Reply to Business Logo Design
    damonharris
    Logo represent you and your business. If it's presentable enough, that means you are credible too in giving services to the clients or customers. That's why it's very important in any business because...
    Today, 06:12 AM
  • damonharris
    Reply to creative business cards
    damonharris
    Choose a design that is creative and effective enough to boost your business and will get the interest of your potential customers. That's what I'm always telling my friends who are in the business. And...
    Today, 06:03 AM
  • Yehoshua
    Cover Layout Feedback
    Yehoshua
    I've been exploring more with minimalism, but still trying to keep things logical. This is a 11x17 cover for a recent undergrad project I've been working on. Does it work? Why or why not? The blue wacked...
    Today, 04:22 AM
  • vaprarts
    Reply to Down selling to clients
    vaprarts
    Now i have no real experience working with clients but in my opinion you did what most designers should do. You are being hired as a designer not an artist. Its our job to create work that makes sense....
    Today, 02:58 AM
  • Buda
    Reply to Zoo Business Card Critique Wanted
    Buda
    I really like the aesthetic.

    Will you do more in the series? You could have a different design for different departments.
    Today, 02:44 AM
Advertisement Advertisement Module
Collapse

Sponsors Sponsors Module
Collapse

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 © 2014 Mediabistro Inc. call (212) 389-2000 or email us
                      Working...
                      X