Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
| Search | Today's Posts | Mark Forums Read
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 February 2nd, 2004, 04:35 PM
Authorized User
Join Date: Jul 2003
Location: Urbana, IL, USA.
Posts: 41
Thanks: 0
Thanked 1 Time in 1 Post
Default submit in If statment not work

I want to check each field (acc_tot_1, ...., acc_tot_?) to make sure it is not blank. If it is I want to give them an alert and take them back to the missing text box...thing is I don't know how many acc_tot_? fields there are, I've created an expandable account area.

my validation code (part of it)
else if (document.RFO.arow.value != 1) {
  for(i=document.RFO.arow.value; i > 1 ; i--){
    if (''==document.RFO.elements['acc_tot_' + i].value){
      alert("Need Amount For Each Account Used");
      document.RFO.elements['acc_tot_' + i].focus();

Say there are three acc_tot_ fields
I do not check acc_tot_1 (won't get into why)
acc_tot_2 is checked...and is blank so the user gets an alert and the cursor goes to the blank text box.
acc_tot_3 is checked and because it is not blank the else statement submits the form.

I don't know what to do here...if I don't have the else statement, the document does not get submitted if there are more than 1 acc_tot field.

Old February 11th, 2004, 12:22 AM
Authorized User
Join Date: Feb 2004
Location: , CT, USA.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts

your code is checking acc_tot_3 and then acc_tot_2, which is not the order that you describe in your scenario. Is that part of your problem?

Also, you're not exiting your for() statement, so as soon as you hit a non-blank acc_tot_X you're going to submit, and your user will never have had a chance to correct the blank one(s).

You need to loop through all your fields and set a flag if one or more is blank, then submit or not based on the value of the flag, rather than including your submit inside the loop in the else clause.

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to submit the different data on single submit pushpa Classic ASP Databases 1 January 24th, 2007 07:10 PM
if statment knightm28 Classic ASP Databases 2 April 1st, 2005 11:08 AM
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
SQL statment arshad mahmood VB Databases Basics 1 July 1st, 2003 02:10 PM

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