473,598 Members | 2,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

1 New Member
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]
Nov 22 '07 #1
1 2284
andho
34 New Member
1. your <form> tag doesnt seem to be closed.
2. the onsubmit="retur n ValidatehostFor m();" 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 ValidatehostFor m();" 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
2298
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 need to: 1. Click a submit button on an asp page, calling another page that saves the contents of that form to a database and then displays
10
6708
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 exiting a form field, if the
4
2181
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 select to the invalid field to force the user to correct the entry. A simple example is at www.brilley.co.uk/TestInfo.htm The problem is that this example works in IE but not in NN or Safari, which do not return focus or select back to the...
5
3061
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 what I'd really like is for the error messages to only be displayed after the validation fails. Is this a feature of the standard ASP.NET validation or will I have to write custom validators if I want to do that?
4
3132
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 controls visible in the onclick event handler, but I do not know how to bring the focus to the bottom section of the page. So basically, when the user clicks the button, everything works correctly in the onclick (all controls are made visible),...
14
3458
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 public member with a return type that is derived from System.Exception? I understand the importance of having clean, concise code that follows widely-accepted patterns and practices, but in this case, I find it hard to blindly follow a standard...
3
3970
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 a couple of problems, which I'll try to describe. But this e-mail will only reproduce one of them, in a "short" example. What I'm generally doing is having each form entry contained in a div, which as a label, an input with some event handlers,...
7
1554
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 button,obviously an error willl be raised. Is there anyway such that when the error is raised the focus goes to first control that has false validation (e.g in our case that control is 5) ? Right now after clicking the save button, none of the control has...
3
5402
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 I'd rather do it like Microsoft Dynamics does and use separate textbox and lookup button. What I have is, simply, is a C# winform, a textbox and a pushbutton. On the textbox, on the validating event of the textbox I check my customer table...
4
1428
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 (new_email) that I'm validating with a very simple script. If the validation fails, the user gets the requisite error message, and the field is blanked out. This all works. The problem is, I want to return focus to the E-mail field AFTER the user clicks...
0
7894
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8284
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8392
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8262
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5437
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2410
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1500
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1245
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.