Link to home
Start Free TrialLog in
Avatar of Dstathakis
Dstathakis

asked on

Having problem with IF statement!

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         
 }       
//-->

Avatar of merphle
merphle

Looks like you're missing a semicolon at the end of your "end if"
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
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.
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
ASKER CERTIFIED SOLUTION
Avatar of Ralf Klatt
Ralf Klatt
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dstathakis

ASKER

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.
Thank you!

d.
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
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
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 ;-))
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
... I know that! ;-)) ... I was just joking! ... you'll get your points one or the other way!!!
Ask an expert at the following link to help reassign points, split points, or create a new question.

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