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, 01:45 PM
Registered User
 
Join Date: Feb 2004
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Form validation & conditional return confirmation

Hi

I have some good form validation code, but I can't figure how to make it return a confirmation statement only if the form validates OK.

Here's the code (s = validation errors):

  if (s!=''){alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+s)
  document.MM_returnValue = (s=='');
    else
return confirm ('This will save your entry so that you can login again and complete the form later. \n Press OK if this is what you want to do.');
}


I get syntax errors with the above. Any help would be greatly appreciated.

Many thanks

Graham

 
Old February 2nd, 2004, 06:10 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: High Wycombe, UK, United Kingdom.
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
Default

I don't think that you can return a Confirm, try :

if (confirm("okay"))
{
    return true;
}
else
{
    return false;
}
 
Old February 2nd, 2004, 06:26 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

It looks to me it's a bracket thing. If you reformat your code it will be easier to see. Take a look at this:
Code:
if (s!='')
{
  alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+s)
  document.MM_returnValue = (s=='');
else
  return confirm ('This will save your entry so that you .....');
}
There is some odd stuff with your brackets going on. Try this instead:
Code:
if (s!='')
{
  alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+s)
  document.MM_returnValue = (s=='');
}
else
{
  return confirm ('This will save your entry so that you .....');
}
Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old February 3rd, 2004, 11:31 AM
Registered User
 
Join Date: Feb 2004
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar and Greg

Many thanks for your help! You were both right and I got what I wanted in the end.

Thanks again, very grateful

Graham




Similar Threads
Thread Thread Starter Forum Replies Last Post
Standalone validation + web form validation morbo Struts 0 August 19th, 2008 04:02 AM
form with conditional questions jcrowley PHP How-To 0 January 30th, 2007 12:02 AM
xsd conditional validation kapar_p XML 4 August 7th, 2006 01:48 PM
Conditional Validation in a DataGrid acorbo ASP.NET 1.0 and 1.1 Professional 0 August 24th, 2004 01:12 PM
conditional form submission moushumi Classic ASP Basics 1 March 30th, 2004 08:12 AM





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