Web Analytics Made Easy -
StatCounter Validation - CodingForum

Announcement

Collapse
No announcement yet.

Validation

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

  • Validation

    Sorry if this seems like a simple problem but my javascript knowledge is a bit limited.

    I basically have a submission form - I have got all the basic validation sorted on it ie empty text felds, at least one check box, email validation etc, however I need to be able to add validation to the following:-

    Two of the text fields 'telephonenumber' and 'mobilenumber' arent requied fields, however I have a checkbox option 'telephone' which if it is checked I need at least one of the two text fields mentioned above to be populated.

    Can any one help with the code needed to validate this?

    Any help would be greatly appreciated - ive been struggling with this for nearly 2 days!

    To start my self off, Ive been trying to get the code to work so that if the checkbox is checked then just the textfield 'telephonenumber' must be filled.

    My code for this is

    if (form.checkboxphone.checked == true && isempty(form.telephonenumber.value))
    message += " Please enter your telephone number.\n";

    However this doent work.

  • #2
    There is no isempty function in javascript unless you specifically made that function.
    Code:
    if (form.checkboxphone.checked == true && form.telephonenumber.value == '')
    {
    message += " Please enter your telephone number.\n";
    }
    should work.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

    Comment


    • #3
      PHP Code:
      if (
          (
      form.checkboxphone.checked == true) &&
          (
      form.telephonenumber.value == '') &&
          (
      form.mobilenumber.value == '')
        ) 
      message += " Please enter a telephone number.\n"
      Should also work, and includes your "mobilenumber" in the conditional.

      Comment


      • #4
        Originally posted by _Aerospace_Eng_ View Post
        There is no isempty function in javascript unless you specifically made that function.
        Code:
        if (form.checkboxphone.checked == true && form.telephonenumber.value == '')
        {
        message += " Please enter your telephone number.\n";
        }
        should work.
        Sorry, I just took that piece of code out of the main body. I had made the isempty function :-

        function isEmpty(s)
        { return ((s == null) || (s.length == 0)) }

        Thanks for your your help - it worked :-)

        Comment


        • #5
          Originally posted by VortexCortex View Post
          PHP Code:
          if (
              (
          form.checkboxphone.checked == true) &&
              (
          form.telephonenumber.value == '') &&
              (
          form.mobilenumber.value == '')
            ) 
          message += " Please enter a telephone number.\n"
          Should also work, and includes your "mobilenumber" in the conditional.
          Thanks for this - I used this as a solution.

          Thanks for your help, it was greatly appreciated.

          Comment

          Working...
          X