Skip navigation
Currently Being Moderated

Quick question on this javascript code. Real simple question...

Mar 7, 2012 9:49 AM

I have 2 bits of javascript code I want to put together so it is just one bit of code. I know this is a simple question but I am just not sure which bits of the second code need to be added and how. Thanks!

 

 

<script type="text/javascript">

function validateForm()

{

var x=document.forms["myForm"]["fname"].value;

if (x==null || x=="")

  {

  alert("First name must be filled out");

  return false;

  }

}

</script>

 

 

 

 

<script type="text/javascript">

function validateForm()

{

var x=document.forms["myForm"]["email"].value;

var atpos=x.indexOf("@");

var dotpos=x.lastIndexOf(".");

if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)

  {

  alert("Not a valid e-mail address");

  return false;

  }

}

</script>

 
Replies
  • bedrich26
    1 posts
    Apr 27, 2012
    Currently Being Moderated
    Apr 27, 2012 3:11 AM   in reply to snarble

    <script type="text/javascript">

    function validateForm()

    {

    var x=document.forms["myForm"]["fname"].value;

    if (x==null || x=="")

      {

      alert("First name must be filled out");

      return false;

      }

    var x=document.forms["myForm"]["email"].value;

    var atpos=x.indexOf("@");

    var dotpos=x.lastIndexOf(".");

    if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)

      {

      alert("Not a valid e-mail address");

      return false;

      }

    }

    </script>

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points