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 ValidatehostFor m()
{
var Ctargetlength = document.form.s torcurtar.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("P lease Enter Hostname in Host webpage");
document.form.h ostname.focus() ;
return false;
}
if (hostname.test( document.form.h ostname.value))
{
alert("Hostname should be aplha numeric");
document.form.h ostname.focus() ;
return false;
}
if (document.form. lob.selectedInd ex < 1)
{
alert("Select Lob From Dropdown list in Host webpage");
document.form.l ob.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_hos tform.asp" method="post" onsubmit="retur n ValidatehostFor m();">-->
<form name="form" action="add_hos tform.asp" method="post" >
<td class="cardtext " style="padding-top:9px; padding-bottom:9px;">
<input class=button type=submit value=SAVE onclick ="return ValidatehostFor m();" >
<input class=button type=button value=CANCEL onClick="window .location='host Main.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_l eft"></td>
<td class="tab_c2_c enter" width="55"><fon t class=
"xs_b_white_tex t">SUMMARY</font></td>
<td class="tab_c2_r ight"></td>
<td class="tab_whit e_left"></td>
<td class="tab_whit e_center" width="55"><a href="#" class=
"xs_b_grey_link " onclick=
"show('detail') ; hide('summary') ;">DETAIL</a></td>
<td class="tab_whit e_right"></td>
<td class="tab_whit e_left"></td>
<td class="tab_whit e_center" width="55"><a href="#" class=
"xs_b_grey_link " onclick=
"hide('summary' );show('storage ');">STORAGE</a></td>
<td class="tab_whit e_right"></td>
<td class="tab_whit e_left"></td>
<td class="tab_whit e_center" width="55"><a href="#" class=
"xs_b_grey_link " onclick=
"hide('summary' );show('comment s');">COMMENTS</a></td>
<td class="tab_whit e_right"></td>
<td class="tab_whit e_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'><opt ion 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]