Solved

How to I get jQuery to Execute an Ajax Call after fixed Digit Entry

Posted on 2015-01-16
3
173 Views
Last Modified: 2015-01-22
I want to use jQuery to do the following:

1. Count the number of characters being entered in an input field and limit the field to six numbers only.
2. When six digits are entered, I want it to compare it to a value in a database
3. If the entered number matches the database entry, then present a "success message"
4. If the numbers do not match, provide a warning.

I know how to use ajax to connect to a database and am using the following piece of code to check if an email already exists in our database.  So I don't need help with points #3 and #4 above, it's just number one and two.

Here's the code I'm using for my email exists.  

$( "#email" ).blur(function() {
			var str = "email=" + $( "#email" ).val();
			var url = "doajax.php?a=popfind";
			$.post(url, str, 
				function(data,status){
    				$( "#result" ).html(data);
  				}
			);
		});

Open in new window


This runs the ajax call when  you leave the field.  What I want is the above modified so that it 1) limits to six numbers only and 2) calls the function after the sixth digit is entered.

Thanks.
0
Comment
Question by:pkonstan1
  • 2
3 Comments
 
LVL 2

Assisted Solution

by:Elxn
Elxn earned 250 total points
ID: 40554208
Have an example of doing this here:  http://girlzunderground.com/ee2.html

I'm using PHP (in the script posted to) to generate the message regarding email matching...
0
 

Accepted Solution

by:
pkonstan1 earned 0 total points
ID: 40555099
Thanks for the php example that "kind of" uses jQuery.

In your example you're using the jQuery to do the database call, but it's not doing the "listening" that jQuery does.

I found what I was looking for here:
http://www.jqueryscript.net/form/Powerful-Form-Validation-Plugin-For-jQuery-Bootstrap-3.html

I would just need to modify the "captach" field to work for a single six digit number.

Or alternatively I have found the whole suite of products at: http://formvalidation.io/ will probably provide what I need.

Thanks.
0
 

Author Closing Comment

by:pkonstan1
ID: 40563895
Upon further research I found the tools I was looking for in other sites. I was originally hoping for just a small piece of jQuery code but that didn't happen.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Link SQL table to Webpage 9 38
uploading multiple image with php 14 19
Can't connect to my database 2 13
masking php string 4 0
There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now