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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:40:32+00:00 2026-05-23T07:40:32+00:00

i was tasked by my team to build a system that will serve as

  • 0

i was tasked by my team to build a system that will serve as programmatic prototype for our next project which will be developed using codeigniter and jquery. since i’m a new comer in web programming, it takes quite sometime for me to solve problems. and the following code has plagued me for two days.

$(function() {
var bln_valid = true;

$('#btn_save').click(function() {
    $('.warning-label').html('');


    if ($('#txt_customer_code').val() == '') {
        // did user provide customer code?
        $('#lbl_customer_code').html('Customer Code has to be filled in.');
        bln_valid = false;
    } else {
        // is the code unique?
        $.post('<?php echo base_url()."index.php/customer/is_code_exists" ?>', {
            txt_customer_code   : $('#txt_customer_code').val()
        },
        function(data) {
            if(data.error == undefined) {
                if (data['code_exists'] == 1) {
                    $('#lbl_customer_code').html('Customer Code is not available.');
                    bln_valid = false;
                }
            } else {
                $('#lbl_customer_code').html('Customer Code is not available.');
                bln_valid = false;
            }
        },'json'
        );                      
    }   

    if (bln_valid == false) {
        return false;
    } else {
        // insert the code to database
        $.post('<?php echo base_url()."index.php/customer/add" ?>', {
            txt_customer_code   : $('#txt_customer_code').val(),
        },
        function(data) {
            if(data.error == undefined) {
                $('#lbl_customer_code').html(data['key']);
                if (data['key'] == '') {
                    $('#lbl_customer_code').html('Failed Saving.');
                    return false;
                } else {
                    $('#lbl_customer_code').html('Successfully saving.');
                }
            } else {
                $('#lbl_customer_code').html('Failed Saving.');
                return false;
            }
        },'json');                      
    }                   
});});

so i want to validate the uniqueness of customer code before i insert it to database. but it seems that the validation and insertion code, both using ajax, are executed almost simultaneously. bln_valid still retains its TRUE value when the insertion is started even though the customer code isn’t unique.

  1. is there a way to allow the insertion code to run after the validation complete? i have read about jquery’s queue but failed to grasp the concept and apply it to solve my problem.
  2. is there a more effective method to achieve the objective of validating and submit data?

i try not to use any plugins because i was told to keep the use of any external works as minimum as possible.

thanks for your help.

  • 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-23T07:40:32+00:00Added an answer on May 23, 2026 at 7:40 am

    Jquery has lot of plugins for ajax submit and validation. Rather than writing your own logic, you can consider using them. I recommend

    1. Jquery form plugin – Which submits the form through ajax. Remove the submit, make a button which on click submits the form through ajax.

    2. Jquery Validation plugin – which validates everything based on the class. You can even write your own logic using .addValidator method.

    Working example here

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

Sidebar

Related Questions

I've been tasked with setting up an automated system that will have to do
I'm part of a testing team and have been tasked with behaving badly using
I've been tasked to create a policy for our organization to determine which developers
My team has been tasked with designing a web application that is workflow driven.
I've been tasked with the the maintenance of a nonprofit website that recently fell
I've been tasked with redesigning part of a ms-sql database structure which currently involves
I've been tasked with updating a series of applications which are performance critical VB.NET
I've been tasked with build an accessible RSS feed for my company's job listings.
I have been tasked to develop an interactive website using java & mysql: using
We were building out the next version of an in-house thick-client application using WPF/Prism

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.