hi all !
I am trying to submit a form using javascript but form is not being submitted.
Following are the code :
<html>
<head>
<script language="javascript">
/***********************Email Validation **************************************/
function echeck(str) {
var at="@"
var dot="."
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if (str.indexOf(at)==-1){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(at,(lat+1))!=-1){
alert("Invalid E-mail ID")
return false
}
if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(dot,(lat+2))==-1){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(" ")!=-1){
alert("Invalid E-mail ID")
return false
}
return true
}
/**********************************************************************************/
/***************************Contact Number Validation ****************************/
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
/*********************************************************************************/
function validate(){
var emailID=document.frmContactUs.txtEmail
if(document.getElementById("Name").value.length==0){
alert("Please Enter Your Name!")
document.frmContactUs.txtName.focus()
}
else if(document.getElementById("Company").value.length==0){
alert("Please Enter Company!")
document.frmContactUs.txtCompanyName.focus()
}
else if ((emailID.value==null)||(emailID.value=="")){
alert("Please Enter your Email ID")
emailID.focus()
return false
}
else if (echeck(emailID.value)==false){
emailID.value=""
emailID.focus()
return false
}
else if(document.getElementById("ContactNo").value.length==0){
alert("Please Enter Contact Number!")
document.frmContactUs.txtContactNo.focus()
}
else if(document.getElementById("Service").value==("Please select one......")){
alert("Please select service!")
document.frmContactUs.listService.focus()
}
else{
alert("inside else statement");
//document.frmContactUs.submit();
document.frmContactUs.submit();
alert("submited");
// document.forms["contactUs"].submit();
return true
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Technology Xpress Info Solutions</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<%--<script type="text/javascript" src="javascript/validation.js"></script>--%>
</head>
<body>
<form id= name="frmContactUs" action="ContactUs" method="post">
<jsp:include page="designpages/header5.jsp" />
<div id="content" class="fixed">
<font color="#F87217" size="4"><strong> <marquee>Technology Xpress Info Solutions Pvt. Ltd.</marquee></strong></font>
<div id="maincontent" class="fixed">
<img src="images/ContactUs.jpg" height="100" width="100" class="img-left"/>
<br/> <p><b>
We will be pleased to make you a part of this large family which is growing very fast.
Please fill the form given below or contact us directly through mail or phone.</b>
</p>
_____________________________________________________________________
<%String strMailSent = null;
strMailSent = (String)session.getAttribute("mailSent");
if(strMailSent!=null){
%>
<font color="red"><br/><%=strMailSent%></font>
<%}
session.removeAttribute("mailSent");
%>
<table cellspacing="15" >
<tr>
<td align="right">Name
<font color="red">*</font>
</td>
<td>
<input type="text" name="txtName" id="Name"/>
</td>
</tr>
<tr>
<td align="right">
Company
<font color="red">*</font>
</td>
<td>
<input type="text" name="txtCompanyName" id="Company"/>
</td>
</tr>
<tr>
<td align="right">
Job Title
</td>
<td>
<input type="text" name="txtJobTitle" id="JobTitle"/>
</td>
</tr>
<tr>
<td align="right">
Email
<font color="red">*</font>
</td>
<td>
<input type="text" name="txtEmail" id="Email" />
</td>
</tr>
<tr>
<td align="right">
Contact No
<font color="red">*</font>
</td>
<td>
<input type="text" name="txtContactNo" id="ContactNo" onkeypress="return isNumberKey(event)" />
</td>
</tr>
<tr>
<td align="right">
Service
<font color="red">*</font>
</td>
<td>
<select name="listService" id="Service">
<option>Please select one......</option>
<option>Oracle e-Business Suit Consulting</option>
</select>
</td>
</tr>
<tr>
<td align="right">
Subject
</td>
<td>
<input type="text" name="txtSubject" id="Subject"/>
</td>
</tr>
<tr>
<td align="right">
Message
</td>
<td>
<textarea name="txtMessage" id="Message">
</textarea>
</td>
</tr>
<tr>
<td align="center" colspan="100%">
<input type="button" name="submit" value="SUBMIT" width="60" height="40" onclick="validate()">
<input type="reset" name="reset" value="RESET" width="60" height="40">
</td>
</tr>
</table>
<font color="red"><center>
Fields marked as * are mandatory
</center> </font>
</div>
<jsp:include page="designpages/contactSidebar.jsp" />
</div>
<div id="round_bottom" ></div>
<jsp:include page="designpages/footer.jsp" />
</form>
</body>
</html>
please help me !!! As it is very urgent
thanks in advance