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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:50:38+00:00 2026-06-01T17:50:38+00:00

I am trying to do some simple form validation using javascript object values. I

  • 0

I am trying to do some simple form validation using javascript object values. I know it’s not “ideal”, but I’m just working with a simple form that doesn’t need to be iron-clad.

Please see my fiddle example: http://jsfiddle.net/6dXd7/3/

I am trying to make sure that each form field has a value. If so, set the value for myObj.fieldID to yes.

Then, when the form is submitted, check every existing myObj.XXX and be sure all their values are yes.

In my example, I am having trouble creating the object, and I don’t know how to cycle through all the objects when the submit button is pressed without specifying each one by name.

Here’s the code in the jsfiddle example linked to above:

<script>
$(document).ready(function () {
    var myObj = {};
    $("input.checkblank").blur(function () {
        var inputID = $(this).attr("id");
        var contents = $("input#" + inputID).val();
        if (contents == "") {
            $(myObj).data(inputID, "no");
        } else {
            $(myObj).data(inputID, "yes");
        }
    });
    $("#verify").click(function () {
        if (myObj.first && myObj.second == "yes") {
            // ***** Trying to get it to scan through ALL existing myObj's and make sure all their values are "yes" *****        
            $('.results').text('all good');
        } else {
            $('.results').text('not good');
        }
    });
});
</script>

<input type="text" name="first" id="first" class="checkblank"><br />
<input type="text" name="second" id="second" class="checkblank">
<a href="#" id="verify">check</a><br />
<p class="results"> </p>

​
​

  • 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-01T17:50:39+00:00Added an answer on June 1, 2026 at 5:50 pm

    You were storing field info in jQuery DATA and trying to check them later not in the same place…

    var obj = {}
    $(obj).data('a','1');
    console.log(obj.a); //this will log null, cause there's no attribute 'a' in 'obj'
    console.log($(obj).data('a')); //this will log '1' :]
    

    instead do this, you should store you data in attributes from native object like this:

    var obj = {}
    obj['a'] = '1'; //obj.a = '1' work's too
    console.log(obj.a); //now it log '1' :]
    

    Also, your verification function is wrong.. it only check if first exists inside myObj and if second exists and is equal to "yes". So your verification function should be something like this:

    $("#verify").click(function() {
        var allFieldsOK = false;
        for ( var field in checkedFields ) {
            if ( !(allFieldsOK = checkedFields[field] ) ) break;
        }
        $('.results').text(  allFieldsOK ? 'all good' : 'not good' );
    });
    

    Here is an update to you jsFiddle, it is working for you purpose and should work if you add more input fields with the class checkblank :]
    http://jsfiddle.net/6dXd7/5/

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

Sidebar

Related Questions

I am trying to do some very simple form validation checking for null or
I am trying to add some simple validation to my asp.net mvc form and
I'm using LiveValidation of livevalidation.com for some simple and more complicated form validation on
I'm just trying to do some simple validation in MVC RC and am getting
I'm trying to reset data in my object bound to a simple form (some
I was trying to place some simple effects on an image using HBox using
I have a PHP form that needs some very simple validation on submit. I'd
I'm new to C# and am trying to add some simple server side validation
I have been requested to create a simple form with JavaScript validation code. I
I am trying to use a textarea form entry which I have some javascript

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.