Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 28th, 2006, 03:46 PM
Registered User
 
Join Date: Dec 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default compare form field to database before submit

I need to compare a value typed into a form field against a list queried from a database to ensure duplicate information is not submitted. This is part of a very long form so I'd like to find a way to alert the user that this field contains a duplicate as a pre-post validation rather than validating it during the form's action and sending the user back to a blank form to start over.

This is an edit to an existing hosted application so I'm trying to keep actual code changes to a minimum.

thanks

 
Old December 29th, 2006, 01:53 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 479
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via MSN to surendran Send a message via Yahoo to surendran
Default

<script language="javascript">
function ckkcom()
{
   if(document.form1.txt1.value==document.form1.txt2. value){
             alert("duplicate values found")
       }
}
</script >
<form name="form1" method="post">
text box 1
<input type="text" name="txt1">

text box 2
<input type="text" name="txt2">

<input type="button" value="Submit" onclick="javascript:ckkcom()" name="btnadd">
</form>

surendran
(Anything is Possible)
http://ssuren.spaces.msn.com
 
Old December 29th, 2006, 07:08 PM
Registered User
 
Join Date: Dec 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks - that's great for comparing two individual form fields. I need to compare one form field to all values in a recordset before page submission. I'm not even sure this can be done but I was thinking that it might be possible to poll the DB and get the recordset I need, then compare the form field value the user enteres to each db recordset value as an array... then again, I'm not exactly array savvy so I don't know if this can all be done client-side before the form data moves along its merry way.

 
Old January 2nd, 2007, 05:42 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 479
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via MSN to surendran Send a message via Yahoo to surendran
Default

yah chelle60,
you can try with ajax, it will help you. it will work client site, ajax will run html, so you can contact the server using ajax tec. learn about ajax using my blog http://ssuren.spaces.msn.com or www.w3schools.com

surendran
(Anything is Possible)
http://ssuren.spaces.msn.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
string compare in table field alxtech SQL Server 2000 1 April 27th, 2007 12:25 AM
Compare only the date portion of a datetime field CricketMaster Access 6 April 27th, 2005 01:06 AM
Adding multiple form field values to database cdenequolo Classic ASP Basics 1 August 17th, 2004 05:38 PM
Validating a form field against a database microchip Classic ASP Basics 2 April 24th, 2004 04:07 PM
How can we submit a form without a submit butto phpsharma BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 4 October 20th, 2003 08:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.