Hello frnds
I have created a webbased form using asp and javascript .. while submitting the form i am validating the fields in the form .it validates the field and returns alert message. but when user clicks on alert box it submits the form instead of focusing to desired field...
I have cascade style webform .so if havent filled field in 2nd sheet and i click on submit button in 4 sheet.. it prompts the alert box but does not focus to 2nd sheet field and instead it submits the form...
here is my part of my code please help me out.....
[HTML]<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript">
function ValidatehostForm()
{
var Ctargetlength = document.form.storcurtar.value
var hostname = /[^a-zA-Z0-9]/g
var re = /[\D]/g
var nbu=/[^a-zA-Z0-9]/g
if (document.form.hostname.value == "")
{
window.alert("Please Enter Hostname in Host webpage");
document.form.hostname.focus();
return false;
}
if (hostname.test(document.form.hostname.value))
{
alert("Hostname should be aplha numeric");
document.form.hostname.focus();
return false;
}
if (document.form.lob.selectedIndex < 1)
{
alert("Select Lob From Dropdown list in Host webpage");
document.form.lob.focus();
return false;
}
return true;
}
</script>
<link rel="STYLESHEET" type="text/css" href="./css/sdmsstyle.css">
<link rel="stylesheet" type="text/css" href="./css/datepicker.css">
<style type="text/css">
td { padding:0px; }
table { padding:0px; }
</style><!--#include file="menu.asp"-->
<title></title>
</head>
<body>
<% if ttype= "NEW" then %>
<!--#include file="./includes/masthead.asp" -->
<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">
<tr>
<!--<form name="form" action="add_hostform.asp" method="post" onsubmit="return ValidatehostForm();">-->
<form name="form" action="add_hostform.asp" method="post" >
<td class="cardtext" style="padding-top:9px; padding-bottom:9px;">
<input class=button type=submit value=SAVE onclick ="return ValidatehostForm();" >
<input class=button type=button value=CANCEL onClick="window.location='hostMain.asp'">
</tr>
</table>
<div style="display: block;" id="summary">
<table>
</td>
<tr>
<td class="cardtext">
<table width="100%" cellpadding="0" cellspacing="0" align="center"
border="0">
<tr>
<!-- <TR><td><img src="./images/transparent.gif" height="24" width=1></td></TR> -->
</tr>
<tr>
<td class="tab_c2_left"></td>
<td class="tab_c2_center" width="55"><font class=
"xs_b_white_text">SUMMARY</font></td>
<td class="tab_c2_right"></td>
<td class="tab_white_left"></td>
<td class="tab_white_center" width="55"><a href="#" class=
"xs_b_grey_link" onclick=
"show('detail'); hide('summary');">DETAIL</a></td>
<td class="tab_white_right"></td>
<td class="tab_white_left"></td>
<td class="tab_white_center" width="55"><a href="#" class=
"xs_b_grey_link" onclick=
"hide('summary');show('storage');">STORAGE</a></td>
<td class="tab_white_right"></td>
<td class="tab_white_left"></td>
<td class="tab_white_center" width="55"><a href="#" class=
"xs_b_grey_link" onclick=
"hide('summary');show('comments');">COMMENTS</a></td>
<td class="tab_white_right"></td>
<td class="tab_white_left"></td>
</tr>
<tr>
<td height="6" colspan="19" class="c2_tint"></td>
</tr>
<tr>
<td colspan="4"></td>
</tr>
</table>
</td>
</tr>
<tr class="cardtext">
<td colspan="2" class="cardtext">HOSTNAME<br>
<input type="text" style='WIDTH: 150px;' name="hostname"></td>
</tr>
<tr class="cardtext">
<td colspan="2" class="cardtext">ALIAS<br>
<input type="text" style='WIDTH: 150px;' name="alias"></td>
</tr>
<tr class="cardtext">
<td colspan="2" class="cardtext">HOST TYPE<br>
<input type="text" style='WIDTH: 100px;' name="hosttyp" value="<%=prod%>"></td>
</tr>
<tr>
<td colspan="2" class="cardtext">LOB<br>
<%
rs.Open lobsel, connpen, 1, 2
Response.Write "<select style='WIDTH: 100px' name='lob'><option selected value=" & lob & ">" & lob & "</option>"
Do While NOT rs.EOF
lob = rs("lob_name")
Response.Write "<option value=" & lob & ">" & lob & "</option>" & vbcrlf
rs.MoveNext
Loop
rs.close
%> </td>
</tr>
</table>
</div>[/HTML]