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

  • SEARCH
  • Home
  • 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 9150171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:34:38+00:00 2026-06-17T11:34:38+00:00

Ok, i have form with few inquiries. I started to write my validation code

  • 0

Ok, i have form with few inquiries. I started to write my validation code for it , but my errors wont show. It founds errors because it changes state of div from hidden to visible, but wont show type of error.

Here is my valform.js

reason = "";
function validateForm(form) 
{
    reason += validateAge(form.age);
    if (reason != "") 
    {
        document.getElementById('erbox').style.visibility = 'visible';
        return false;
    }
    return true;
}

function validateAge(fld)
{
    function isNumber (o) 
    {
        return ! isNaN (o-0);
    }

    var error ="";
    var x=fld.value;
    if (x==null || x=="" )
    {
        error="Age must be filled";
    }
    else if (isNumber(x)==false) 
    {
        error="Your age is not numeric value!";
    }
    else if (x<18) 
    {
        error = "You need to be 18 or older!";
    }
    return error;
}

And here is my html form:

<div id="upform">
<form name="lastcheck" action="lastcheck.php" method="post" onsubmit="return  
    validateForm(this);">
    Location: <input type="text" name="locationcity">
    Country:  <input type="text" name="country">
    Gender:  <input type="radio" name="group1" value="w"> Woman<br>
    <input type="radio" name="group1" value="m"> Man<br>
    Age: <input type="number" name="age" size="4" maxlength="2">
    <input type="submit" value="Submit">
    <div style="visibility:hidden" id="erbox">Next error(s) occured: 
    <script type="text/javascript"> document.write.lastcheck('reason');
    </script>
    </div>
    </form> 
</div>

I included js file in header like this:

<script src="js/valform.js"></script>

So for now when it error occurs in AGE field my hidden error form becomes visible but no info about errors.

I have another problem, still learning javascript:

so wanted to add radio button validation and it breaks my whole validation:

function vGender(fld) {

var x = fld.value;


var i = 0;
while (i < x.length) {
    if (x[i].checked) formValid = true;
    i++;        
}

if (!formValid) error = "blabla";
return error;
}​

and i added another reason at top like this:

reason += vGender(form.radios);
  • 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-17T11:34:39+00:00Added an answer on June 17, 2026 at 11:34 am
    document.write.lastcheck('reason'); 
    

    That would populate your div on load – your validation function is only showing it, but not populating it with a new message so it’s empty.

    Try this:

    if (reason != "") {
        var box = document.getElementById('erbox');
        box.style.visibility = 'visible';
        box.innerHTML = 'Next error(s) occurred: ' + reason; // here you go
        return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form with a few entry fields that have validation rules. Next
I have form with few text boxes which goes through validation (both server and
I have a form which has a few fields and a recaptcha code at
I have a form with a few buttons which execute code when pressed like
I have a simple form with a few required field validators and a validation
I have form with few buttons and I want to know what button is
I have problem with TinyMCE editor. I have form with few text fields and
I have a form with a few input fields. When a user clicks on
i have form in drupal which uploads images and has got few checkboxes in
I have a form with a table source, the form has a few fields

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.