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

                      • HiddenDev
                        Reply to Hi!!
                        HiddenDev
                        Welcome Josh!

                        You won't really see me posting much as I'm mostly here to learn.
                        Never the less nice to "meet" you!
                        Today, 07:49 AM
                      • livingdead
                        Help: Identify the font please.
                        livingdead
                        Hello.

                        I was looking for a thread where people can keep on asking members to help identify fonts but couldn't find one.

                        Anyway, please let me know if you recognize the attached...
                        Today, 05:49 AM
                      • PanToshi
                        Reply to Hi!!
                        PanToshi
                        Hi Josh 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, 04:05 AM
                      • FrontEndDev99
                        Payment gateways
                        FrontEndDev99
                        I'm curious to hear about some experiences with common payment gateways....
                        I had been using paypal, but I had a few customers file complaints 5 mins after they ordered, and paypal took the money...
                        Today, 03:00 AM
                      • FrontEndDev99
                        Hi!!
                        FrontEndDev99
                        Hi!! I'm Josh! I'm new here, and look forward to meeting some peeps...
                        Today, 02:56 AM

                      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