Solved

Having problem with IF statement!

Posted on 2003-12-04
13
371 Views
Last Modified: 2010-04-17
Can someone please tell me what I'm doing wrong, I can't seem to get to work!
d.

<!--// Hide from old browsers
function validatev() {

   var SSN = document.entryform1.cssn.value;
   var LNAME = document.entryform1.lname.value;
   
   
 <!--//User hasn't enter anything //-->
    if(SSN!="" && LNAME!=""){
               alert("You MUST fill in Social Security Number \r\n or Last,First,M \r\n before Submitting")
            return false;
         }
 <!--//User has enter LNAME - SSN //-->         
       else if (SSN=="" && LNAME!=""){
                return true;
         }  
 <!--//User has enter SSN -  NOT LName //-->             
       else  (SSN!="" && LNAME==""){
              return true;
             }
      end if         
 }       
//-->

0
Comment
Question by:Dstathakis
  • 4
  • 4
  • 2
  • +2
13 Comments
 
LVL 3

Expert Comment

by:merphle
ID: 9877042
Looks like you're missing a semicolon at the end of your "end if"
0
 
LVL 10

Expert Comment

by:D_M_D
ID: 9877057
Here you go...

<!--// Hide from old browsers
function validatev() {

   var SSN = document.entryform1.cssn.value;
   var LNAME = document.entryform1.lname.value;
   
   If (SSN == ""){
      alert ("Please enter a Social Security Number.");
      document.entryform1.cssn.focus();
      return false;
   }else if (LNAME == ""){
      alert ("Please enter a Last Name.");
      document.entryform1.lname.focus();
      return false;
  }else{
    // all's good
     return true;
  }
//-->

That should do it...

--------
D_M_D
0
 
LVL 3

Expert Comment

by:merphle
ID: 9877071
Gah, that's what I get for switching between languages too frequently. No "end if" in Javascript. Just delete that line and you're good to go.
0
 
LVL 10

Expert Comment

by:D_M_D
ID: 9877502
Here's a full example...  Just copy and paste all the code into a new file, if you need to ....

<html><head>
<script language="Javascript">
<!--// Hide from old browsers

function validatev(formObj) {
   var SSN = formObj.cssn.value;
   var LNAME = formObj.lname.value;

   if (SSN == ""){
      alert ("Please enter a Social Security Number.");
      formObj.cssn.focus();
      return false;
   }else if (LNAME == ""){
      alert ("Please enter a Last Name.");
      formObj.lname.focus();
      return false;
  }else{
    // all's good now you can submit the form or do what ever
     return true;
  }
}
//--></script>
</head><body>
<form name="entryform1">
<input type="text" name="cssn"><br>
<input type="text" name="lname"><br>
<input type="button" name="sbutton" value="ok" onClick="validatev(document.entryform1);">
</form></body></html>

--------
D_M_D
0
 
LVL 15

Accepted Solution

by:
Raisor earned 500 total points
ID: 9878014
Hi,

While you submitted I was still working at a solution --> This would have been mine:

<html>
<head>
<script Language="JavaScript">

function validRequired1(entryform1,thefield)
{

  var result = true;
 
  if (entryform1.value == "")
  {
    alert('Please enter a value for the "' + thefield +'" field.');
    entryform1.focus();
    result = false;
  }
 
  return result;
}

function validRequired2(entryform1,thefield)
{

  var result = true;
 
  if (entryform1.value == "")
  {
    alert('Please enter a value for the "' + thefield +'" field.');
    entryform1.focus();
    result = false;
  }
 
  return result;
 
}

function validateForm(entryform1)
{

  if (!validRequired1(entryform1.cssn,"Social Security Number"))
    return false;

  if (!validRequired2(entryform1.lname,"Your Name"))
    return false;
 
  return true;
 
}

</script>
</head>
<body>
<form method="GET" action="validate.html" onsubmit="return validateForm(this)">
<font face="verdana, geneva, helvetica" size="2"><p align="left">
Social Security No.: <input size="32" name="cssn"><br>
Your Name: <input size="32" name="lname"><br>
</p>
<p>
<input type="submit" value="Register" name="submit"></p>
</font>
</form>
</body>
</html>



... but D_M_Ds' solution was absolutely right and correct!!! --> I just wanted to share MY result!


Best regards, Raisor
0
 

Author Comment

by:Dstathakis
ID: 9879699
I'm sorry, I click on the wrong Accepted Answer.
I wanted to Accepted from D_M_D's

I don't know how to fix my mistake!

d.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Dstathakis
ID: 9879702
Thank you!

d.
0
 
LVL 10

Expert Comment

by:D_M_D
ID: 9882017
Can an administrater please tell me if there is a way to correct what answer was accepted as the Author accepted the wrong answer?

thanks,
D_M_D
0
 
LVL 15

Expert Comment

by:Raisor
ID: 9882050
Hi,

If nothing helps and there's no way to correct this, I'll open a question and assign the necessary points to you D_M_D ... but there'll be certainly a way!


Best regards, Raisor
0
 
LVL 15

Expert Comment

by:Raisor
ID: 9882060
PS @D_M_D -> my answer was not wrong at all ... it was only that yours was supposed to be accepted and mine was chosen by mistake ;-))
0
 
LVL 10

Expert Comment

by:D_M_D
ID: 9882210
I know your answer was also correct.  I didn't mean to imply that your answer was incorrect, just that the author accepted the anwers as there solution in error...

--------
D_M_D
0
 
LVL 15

Expert Comment

by:Raisor
ID: 9882757
... I know that! ;-)) ... I was just joking! ... you'll get your points one or the other way!!!
0
 
LVL 2

Expert Comment

by:jtbalogh
ID: 9886298
Ask an expert at the following link to help reassign points, split points, or create a new question.

http://www.experts-exchange.com/Community_Support/
your question reference number is Q_20816741
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
endX challenge 2 64
How to get boolean result of md5sum from two files in powershell 8 73
Apps blocked by Java 9 64
Auto-indent certain lines in Notepad++ 10 35
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

863 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

23 Experts available now in Live!

Get 1:1 Help Now