# What's wrong with my code?

**URL:** <https://forum.kirupa.com/t/whats-wrong-with-my-code/326581>\
**Category:** Uncategorized\
**Created:** [December 27, 2011, 3:00am UTC](https://forum.kirupa.com/t/whats-wrong-with-my-code/326581 "2011-12-27T03:00:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jackmike008](https://avatars.discourse-cdn.com/v4/letter/j/3e96dc/32.png) [@jackmike008](https://forum.kirupa.com/u/jackmike008)\
**Post date:** [December 27, 2011, 3:00am UTC](https://forum.kirupa.com/t/whats-wrong-with-my-code/326581/1 "2011-12-27T03:00:49Z")

</div>

I want to give alerts when either of the two text fields are inputed wrong

\<html\>  
\<head\>  
\<script type=“text/javascript”\>  
function validateForm()  
{  
var x=document.forms[“myForm”][“fname”].valu…  
if (x==null || x=="")  
{  
alert(“First name must be filled out”);  
return false;  
}  
}  
{  
var x=document.forms[“myForm”][“email”].valu…  
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\>  
\</head\>

\<body\>  
\<form name=“myForm” action=“demo\_form.asp” onsubmit=“return validateForm()” method=“post”\>  
First name: \<br/\>\<input type=“text” name=“fname”\>  
\<br/\>  
Email:\<br/\> \<input type=“text” name=“email”\>  
\<input type=“submit” value=“Submit”\>  
\</form\>  
\</body\>

\</html\>
