Announcement

Collapse
No announcement yet.

javascript form validation: select box

Collapse
X
  • 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

                      Search

                      Collapse

                      Advertisement

                      Collapse

                      Latest Topics

                      Collapse

                      • gogogo
                        need critique
                        gogogo
                        hello~
                        I've been learning illustrator thru lynda.com and to practice i gave myself a project and wanted to see if i can get some critique.
                        its a slight infographic ish content. thanks!...
                        Today, 09:24 PM
                      • HawtTuna
                        Reply to Critique Me...
                        HawtTuna
                        Hello,

                        From what I can see here, I really can't judge your work. From the screenshot you posted, you seem to be technically proficient in Adobe Illustrator. Most of these seem to be self-initiated...
                        Today, 08:18 PM
                      • KitchWitch
                        Reply to Newcomer
                        KitchWitch
                        Hi Ace 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 anything...
                        Today, 07:55 PM
                      • PrintDriver
                        Reply to Photoshop on disc
                        PrintDriver
                        Get yourself a backup drive and mirror your system to that. Macs have Time Machine and I'm sure PCs have something similar.
                        I have to say, it's saved me days of headache. Never used to do it. But...
                        Today, 05:35 PM
                      • Aceh0le21
                        Newcomer
                        Aceh0le21
                        Hey everyone, my name is Wayne. I'm 32 from Philadelphia,PA. I have been slowly teaching myself more and more Adobe Photoshop cs6 and have used what little skill I have acquired to make some custom photos...
                        Today, 02:04 PM

                      GDF A division of Mediabistro Holdings Adweek | Mediabistro | Clio | Film Expo Group Contact Us | Terms of Use | Privacy Policy Copyright 2016 Mediabistro Holdings
                      Working...
                      X