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 6138751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:54:18+00:00 2026-05-23T17:54:18+00:00

This is part of an assignment. Everything that’s supposed to work, already works, but

  • 0

This is part of an assignment. Everything that’s supposed to work, already works, but there’s something that bothers me. The only purpose of the code so far is to test our ability to validate from data. Anyway, right now the validate() function is attached to a submit button:

<input type="submit" value="Find Love" onclick="validate()">

When any validation fails, all the text boxes, drop downs, etc. are cleared, but I want them to retain their values and just focus on the first incorrect value (retaining their values is more important to me at this point). The actual Does that require some modification of the onclick function or a different function all together? Please help. If you need to see the javascript I can post that as well.

function validate()
{
var blnValid = true;

if(isBlank("txtFName"))
{
    blnValid = false;
    alert("First name cannot be blank!")
    document.getElementById("txtFName").focus();
}

if(blnValid)
{   
    if(isBlank("txtLName"))
    {
        blnValid = false;
        alert("Last name cannot be blank!")
        document.getElementById("txtLName").focus();
    }
}
if(blnValid)
{
    if(isBlank("txtAge"))
    {
        blnValid = false;
        alert("Age cannot be blank!")
        document.getElementById("txtAge").focus();
    }
}
if(blnValid)
{
    var strInput = document.getElementById("txtAge").value;
    if(!isInt(strInput))
    {
        blnValid = false;
        alert("You must enter a valid number in the age field.")
        document.getElementById("txtAge").select();
    }
}
if(blnValid)
{
    if(document.getElementById("selUserGender").selectedIndex <= 0)
    {
        alert("Please select your gender");
        blnValid = false;
    }
}
if(blnValid)
{
    if(document.getElementById("selFindGender").selectedIndex <= 0)
    {
        alert("Please select your gender");
        blnValid = false;
    }
}
if(blnValid)
{
    blnChecked = false;
    arRadio = document.forms[0].rdbAgeRange;
    for (var i = 0; i < arRadio.length; i++)
    {
        if(arRadio[i].checked)
        {
            blnChecked = true;
            break;
        }
    }
    if (!blnChecked)
    {
        alert("You must select an age group.");
        blnValid = false;
    }
}
if(blnValid)
{
    if(!document.getElementById("chkSkeeball").checked
        && !document.getElementById("chkAir").checked
        && !document.getElementById("chkCliff").checked
        && !document.getElementById("chkHamster").checked)
    {
        blnValid = false;
        alert("You must select a hobby.")
    }   
}

return blnValid;
}


function isInt(strValue)
{
var validNums = "0123456789";
var blnIsNumber = true;
var tempChar;

for (var i = 0; i < validNums.length; i++)
{
    tempChar = strValue.substr(i, 1);
    if (validNums.indexOf(tempChar) == -1)
    {
        return false;

    }
}
return true;
}

function isBlank(elementID)
{
if(document.getElementById(elementID).value.length == 0)
{
    return true;
}

return false;
}
  • 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-05-23T17:54:19+00:00Added an answer on May 23, 2026 at 5:54 pm

    Your problem is actually your HTML. Nothing in your Javascript is going to clear the elements but because you’re using onClick the form is actually submitting anyway. I assume that it probably just submits back to the page and clears everything. Instead of onClick use onSubmit in the form element:

    <form method="post" action="url_of_action" onSubmit="return validate()">
    

    If it’s not valid it will prevent the form from submitting.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(this is indirectly a part of a much larger homework assignment) I have something
Part of this assignment includes printing out on the display the current equation that
This is part of a homework assignment. I've got several questions asking find the
This part of my code works fine: #include <stdio.h> int main(){ //char somestring[3] =
This part of an app that I am working on, I have the following
This is part of an assignment to complete a word search. I have to
This is in relation to a homework assignment but this is not the homework
As part of an assignment, I'm supposed to write to a file using system
This is part of an assignment however I just asking for clarification: Load data
This was a 2 part assignment. first I had to figure out how to

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.