/    Sign up×
Community /Pin to ProfileBookmark

Form Validation…With a Twist…

I have a form I am working on (unable to give and web page at the moment because it is not a live site yet still in the development stage) and I need to do a form validation. I am REALLY new to Javascript and I am starting to understand the basic form validation, however what I have is something a little different.

The form has a list of things that a customer needs to fill out (name, address etc.). However the problem comes in when they are bringing a guest with them, or they are renting a hotel room for the night. I need to have the validation catch if they say yes to a guest then they need to enter the guest name (and if they don’t put the guest name in it gives and error). If they say yes to a Hotel, they need to enter Credit Card information.

I have looked at some web sites and even had someone suggest a looping javascript but I either really don’t get it or the web sites are not exactly suiting my needs. Being new to this makes parts of this really hard for me to translate what they are telling me to the in formation I have. ?

Thanks so much…

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@oleragNov 07.2003 — 
  • 1. Are you kicking validation from a button. If so, add

    "onClick="validateForm(this.form)" to your button HTML.


  • 2. Your "validateForm(form)" function would...

    a) Check if the Guest ?checkbox? is checked. If so, test

    if "Guest Info" is filled appropriately.

    b) Check if "Hotel" ?checkbox? is checked. If so, have the

    credit card info validated. The credit-card info would

    probably need to include some additional string validation

    check(s) as you determine appropriate.


  • 3. If the function's validation is successful, submit the

    form otherwise show the appropriate alert information.


  • A complete coding sequence can be shown if you provide

    your HTML in the thread so the object types/names are

    identified.
    Copy linkTweet thisAlerts:
    @celtic5544authorNov 07.2003 — Actually what I have is a Submit image... which we have working with ASP script. I just found out from my boss that we also want to have something were the error they get all the error's at once. Like the following problems....and then it lists them.

    This is what I have so far...

    <script language="JavaScript" type="text/JavaScript">

    function submitIt(editForm){

    if (editForm.strRegType.selectedIndex== "") {

    alert ("Please Pick Registration Type")

    }

    if (editForm.strFirstName.value == ""){

    alert ("Please Enter First Name")

    return false

    }

    return true

    }

    </script>
    Copy linkTweet thisAlerts:
    @oleragNov 07.2003 — To compile all errors during one validation submission,

    create an array and store all of the alert messages into

    the array's element(s). If the array's length is greater

    than 0, at least one error occurred. Then , iterate thru

    the array to display the errors in the desired presentation.
    ×

    Success!

    Help @celtic5544 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.17,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @nearjob,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...