Web Analytics Made Easy -
StatCounter simple form validation assistance please ;) - CodingForum

Announcement

Collapse
No announcement yet.

simple form validation assistance please ;)

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

  • simple form validation assistance please ;)

    I dont know if I'm just a moron, or if its the lack of sleep or what, but I cant get this d*mn thing to work, any insight would be greatly appreciated thanks!



    <!--
    function checkData()
    {
    var correct = true

    if (document.LSL.1.value == ""){correct = false; alert("Please Enter Your Name"); document.LSL.1.focus()}

    if (document.LSL.2.value == ""){correct = false; alert("Please Enter Your Age"); document.LSL.2.focus()}

    if (document.LSL.2a.value == ""){correct = false; alert("Please Enter Your Ethnicity"); document.LSL.2a.focus()}

    if (document.LSL.3.checked == false){correct = false; alert("Please answer number 3")}

    if (document.LSL.4.value == ""){correct = false; alert("Please answer number 4");form.4.focus()}

    if (document.LSL.5.checked == false){correct = false; alert("Please answer number 5")}

    if (document.LSL.6.checked == false){correct = false; alert("Please answer number 6")}

    if (document.LSL.7.checked == false){correct = false; alert("Please answer number 7")}

    if (document.LSL.8.checked == false){correct = false; alert("Please answer number 8")}

    if (document.LSL.9.checked == false){correct = false; alert("Please answer number 9")}

    if (document.LSL.10.checked == false){correct = false; alert("Please answer number 10")}

    if (document.LSL.11.checked == false){correct = false; alert("Please answer number 11")}

    if (document.LSL.12.checked == false){correct = false; alert("Please answer number 12")}

    if (document.LSL.13.checked == false){correct = false; alert("Please answer number 13")}

    if (document.LSL.14.checked == false){correct = false; alert("Please answer number 14")}

    if (document.LSL.15.checked == false){correct = false; alert("Please answer number 15")}

    if (document.LSL.16.checked == false){correct = false; alert("Please answer number 16")}

    if (document.LSL.17.checked == false){correct = false; alert("Please answer number 17")}

    if (document.LSL.18.checked == false){correct = false; alert("Please answer number 18")}

    if (document.LSL.20.value == ""){correct = false; alert("Please answer number 20"); document.LSL.20.focus()}

    if (document.LSL.21.checked == false){correct = false; alert("Please answer number 21")}

    if (document.LSL.22.checked == false){correct = false; alert("Please answer number 22")}

    if (document.LSL.23.checked == false){correct = false; alert("Please answer number 23")}

    if (document.LSL.24.checked == false){correct = false; alert("Please answer number 24")}

    if (document.LSL.25.checked == false){correct = false; alert("Please answer number 25")}

    if (document.LSL.26.checked == false){correct = false; alert("Please answer number 26")}

    if (document.LSL.27.checked == false){correct = false; alert("Please answer number 27")}

    if (document.LSL.28.checked == false){correct = false; alert("Please answer number 28")}

    if (document.LSL.29.checked == false){correct = false; alert("Please answer number 29")}

    if (document.LSL.30.checked == false){correct = false; alert("Please answer number 30")}

    if (document.LSL.31.checked == false){correct = false; alert("Please answer number 31")}

    if (correct == true){alert("HOLY CRAP IT WORKED!")}
    return correct
    }
    //-->

    <form onSubmit="return checkData()" name="LSL" action="custom/formhandler.asp" method="post">


    Could someone PALEASE! take the time to tell me where I'm screwing up at? obviously I'm far from a .js guru, cheers!

  • #2
    1) If you want to access the form elements with the numerical index you must use brackets, e.g.: document.forms['LSL'][1].value

    2) You cannot give your elements names such as "2a". The first character must not be a number. If you give your form elements names such as "1", you cannot access them like document.forms['LSL'][1], because this will return the 2nd form element of the form rather than the form element with a name of "1".

    3) You happen to have many "if (document.LSL.SOME_VALUE.checked == false) ...". If these form elements are checkboxes it's rather silly, because you would require the user to check these all (so, you could just leave them out). So I assume these are inputs of type radio. However, to make sure that one radio of a collection is checked, you must get the collection of the radios like document.forms['LSL'].RADIO_COLLECTION_NAME, and iterate through the collection to verify that one of them is checked.

    4) Figure out a more appropriate way to display invalid inputs. In worst case, the user would have to click nearly 3 dozens of alerts away. Would be really annoying, i guess.

    dumpfi
    Last edited by dumpfi; Aug 1, 2005, 09:10 PM.
    "Failure is not an option. It comes bundled with the software."
    ....../)/)..(\__/).(\(\................../)_/)......
    .....(-.-).(='.'=).(-.-)................(o.O)...../<)
    ....(.).(.)("}_("}(.)(.)...............(.)_(.))¯/.
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
    Little did the bunnies suspect that one of them was a psychotic mass murderer with a 6 ft. axe.

    Comment


    • #3
      Could someone please tell me wtf I'm doing wrong here? I just know its got to be some stupid mundane little syntax error or something. But my script posts without any of my stuff doing its job. needless to say I still suck at .js, but am trying

      Mucho thanks for anyone that takes the time...



      <script language="Javascript">
      <!--
      function checkData()
      {
      var correct = true

      if (document.forms.[LSL][1].value == ""){correct = false; alert("Please Enter Your Name"); document.forms.[LSL][1].focus()}

      if (document.forms.[LSL][2].value == ""){correct = false; alert("Please Enter Your Age"); document.forms.[LSL][2].focus()}

      if (document.forms.[LSL][2a].value == ""){correct = false; alert("Please Enter Your Ethnicity"); document.forms.[LSL][2a].focus()}

      if (document.forms.[LSL][3].checked == false){correct = false; alert("Please answer number 3")}

      if (document.forms.[LSL].checkboxgroup3 == false){correct = false; alert("Please answer number 3")}


      if (correct == true){alert("HOLY **** IT WORKED!")}
      return correct
      }
      //-->
      </script>


      <form onSubmit="return checkData()" name="LSL" action="/cgi/customhandler.asp" method="post">

      Comment

      Working...
      X