473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Return focus to failed validation field after user clicks to get rid of error message

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]
Nov 22 '07 #1
1 2274
andho
34
1. your <form> tag doesnt seem to be closed.
2. the onsubmit="return ValidatehostForm();" attribute is not in the uncommented form tag, but it is correclty specified in the commented out tag. Maybe its an asp thing. (i dont know asp)
3. no need for "return ValidatehostForm();" in the onclick event of the save button
Nov 22 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: fig000 | last post by:
Hi, I'm relatively new to Javascript so please bear with me on what might sound like silly questions. This is what I want to do: I'm working in classic asp (I have to for this project). I...
10
by: CES | last post by:
All, I'm having a problem returning focus back to an input field in Netscape. The code works in IE and Opera but not in netscape6+. Basically I have a function that is called upon...
4
by: Roger Withnell | last post by:
I want to validate the data entered into a form text field by calling a function with onblur, doing the validation and, if the input is invalid, giving an alert to the user and returning focus and...
5
by: Helen | last post by:
Hi I'm using ASP.NET's standard validators to display error messages when people don't fill in required fields on my form. The error messages currently show as soon as the form is loaded, but...
4
by: PK9 | last post by:
I have a button at the top of my page that I have an onClick event handler for which makes some new controls (at the bottom of my page) visible. When the user clicks the button I make the new...
14
by: dcassar | last post by:
I have had a lively discussion with some coworkers and decided to get some general feedback on an issue that I could find very little guidance on. Why is it considered bad practice to define a...
3
by: jab3 | last post by:
Hello. I"m new to this group, and to JavaScript in general, so please forgive me if I breach local etiquette. I'm trying to implement some client-side 'dynamic' validation on a form. I'm having...
7
by: saurabh | last post by:
Hey, I have a form in which there are say 10 fields. I am using validator control for all the fields. suppose user forgets to fill field no. 5, 8 , 9 and 10. So on clicking the save...
3
by: Patrick [MSFT] | last post by:
Let me preface this with the goal I'm trying to achieve is mimic a feature of another language (Dexterity used by Microsoft Dynamics) and so while a filling a drop down list is a workable solution...
4
by: vozzek | last post by:
(bad joke, I know) Alright, I'm an almost total java rookie, so please don't laugh (a snicker or chuckle would be okay I guess...) I've got a form (newloginform) with an E-mail field...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.