Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8958175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:09:05+00:00 2026-06-15T15:09:05+00:00

I want to validate a form but I want to have 9 different functions

  • 0

I want to validate a form but I want to have 9 different functions to validate the form. Which validation function gets used should be determined by a slider on the screen, or rather by the value in the span “range” which is controlled by the slider)

I can validate the form fine if I’m just using one function to do so with the below:

<script>
    function validateFormMethod1() {
        // do my validation stuff here
    }
</script>

<form method="post" action="whatevermailscript.php"name="GuestInfo" onSubmit="return validateFormMethod1();">
    <input type="submit" value="Send" name="submit" />
    <span>Guests</span>
    <span id="range">1</span>
    <input id="scaleSlider" type="range" value="1" min="1"  max="9" step="1" onchange="showValue(this.value) ; showOrHide(this.value)"/>

But how can I add to this this so that if range.value==2 validateFormMethod2 would get called instead of validateFormMethod1?


Update 3:

<script>


   function validateFormMethod0() {

    }  

    function validateFormMethod1() {
       window.alert("Method 1");
       return false;
    }

    function validateFormMethod2() {
        window.alert("Method 2");
        return false;
    }


    function validateFormMethod3() {
      window.alert("Method 3.");
      return false;
    }


    function validateFormMethod4() {
       window.alert("Method 4.");
       return true;
    }





    var validationFunctions = [
    validateFormMethod0,
   validateFormMethod1,
   validateFormMethod2,
   validateFormMethod3,
    validateFormMethod4

];
    function validateForm() {    

     var range = document.getElementById("range");

    validationFunctions[range.innerHTML]();
}


</script>

Still cant quite get this working as suggested but this serves my purpose:

 function validateForm()
{


 var range = document.getElementById("range");


   if (range.innerHTML == "1")
    {
        // do my validation stuff for case one here


    }


   if (range.innerHTML == "2")
    {
        // do my validation stuff for case two here


    }

} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:09:06+00:00Added an answer on June 15, 2026 at 3:09 pm

    Use an array of functions.

    var validationFunctions = [
       validateFormMethod1,
       validateFormMethod2,
       validateFormMethod3,
       ....
    ];
    
    function validateForm() {        
        validationFunctions[range.value]();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to validate a form fields (text) input. It should only be a
I have a form in which I am using remote validation to check if
I have one model but two different forms ,one form i am saving through
I have a JQuery to show a remote validation message but I only want
I am using jquery validation plugin to validate my form. I have one field
I have a form that has target=_blank on submit. I want to validate the
I'm using Inline Form Validation Engine to validate a form. Now I want to
Hi I want to validate a form input so it only takes the numbers
Im using asp.net webforms. c# I want to validate a form. In the codebehind
I want to validate a registration form that accepts an email address in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.