Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Pro JSP
|
Pro JSP Advanced JSP coding questions. Beginning questions will be redirected to the Beginning JSP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro JSP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 23rd, 2005, 10:59 PM
Authorized User
 
Join Date: Nov 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to vanjamier Send a message via AIM to vanjamier Send a message via MSN to vanjamier Send a message via Yahoo to vanjamier
Default Javascript fdoesnt work..

Hi i did a javascript to check if the fields are empty..and if prevent submit otherwise proceed as normal.
But the javascript doesnt check anything.. i dont understand why.

Code:
<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<script language="JavaScript">
function verify() {
var themessage = "You are required to complete the following fields: ";
if (document.form1.name.value=="") {
themessage = themessage + " - Name";
}
if (document.form1.login.value=="") {
themessage = themessage + " -  Win2k Login ID";
}
if (document.form1.department.value=="") {
themessage = themessage + " -  Department";
}
if (document.form1.center.value=="") {
themessage = themessage + " -  center";
//alert if fields are empty and cancel form submit
if (themessage == "You are required to complete the following fields: ") {
document.form.submit();
}
else {
alert(themessage);
return false;
   }
}
</script>
</HEAD>
</HEAD>
<BODY>
<form name=form1 method="post" action="" enctype="multipart/form-data">
<P align=center><STRONG>Application Form For New Mobile User</STRONG></P>
<P align=left></P>
<STRONG>Please fill out the particulars:

<DIV align=center></STRONG>&nbsp;<STRONG>Personal Particulars</STRONG> <BR>
<br>Name:&nbsp;<INPUT size=14 name=name onKeyPress  ="if (event.keyCode < 65 || event.keyCode > 122) event.returnValue  = false;">&nbsp; 
Win2k Login Id: <INPUT size=15 name=login onKeyPress  ="if (event.keyCode < 65 || event.keyCode > 122) event.returnValue  = false;">&nbsp;
Login Type: <SELECT name=login>
            <option value="super">Super
            <option value="normal" selected>Normal
            <option value="Admin">Admin</option>
            </SELECT><BR><BR>
Department: <INPUT size=16 name=department onKeyPress="if (event.keyCode < 65 || event.keyCode > 122) event.returnValue  = false;">&nbsp; Cost 
Center: <INPUT size=5 name=center></DIV>
<DIV align=center>&nbsp;
</DIV>
<DIV align=center>
Remarks : <INPUT size=45 name=remarks><BR><BR></DIV>
<DIV align=center>
<TABLE cellSpacing=2 cellPadding=2 align=center>
  <TR>
    <TD><INPUT type=reset value=Reset id=reset1 name=reset1></TD>
    <TD><INPUT type=submit value=Submit name=submit onclick="verify();"></TD></TR></TABLE></DIV>
</form>
</BODY>
</HTML>
I hope someone out there can point out the mistake.
Thanks in advance
__________________
Education ruined me
 
Old February 8th, 2005, 05:53 PM
Authorized User
 
Join Date: Nov 2003
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sonicDace Send a message via MSN to sonicDace Send a message via Yahoo to sonicDace
Default

Try changing your submit button to a normal button. That might be causing your form to submit before your function is invoked, besides, the validate function is submitting the form anyway ;)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript isnt work well on my aspx page msbsam ASP.NET 2.0 Professional 1 July 11th, 2008 08:00 AM
Chapter 1 Ctrl+F5 don't work, F5 does work? jimboak BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 7 June 29th, 2008 03:46 AM
stop current javascript function using javascript sakthi Javascript 3 June 2nd, 2008 03:30 PM
Hour Diff in javascript doen's work well gabrieldcr2 Javascript 1 April 3rd, 2008 12:47 AM
javaScript function in asp.net not work in firefox rsanuj ASP.NET 1.x and 2.0 Application Design 1 February 8th, 2007 11:37 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.