Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
|
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics 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 August 20th, 2007, 06:43 AM
Registered User
 
Join Date: Aug 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to PrincessDreamz
Default A single JSP page havin one submit & normal button

Hi,
I have a single jsp wherein there is a single submit button which does all the validations when the form is submitted and a normal button which checks for just 2 validations and depending on that queries the database to get the rest of the results.Problem i am facing is Submit buttons functions are working fine but i am not able to code the normal button functons. Please refer the code.how should i make the normal button validate the first 2 fields and then go forward to act as a submit button?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%@ page info="eAssociate Feedback" language="java" import="java.util.*, java.io.*, java.net.*, java.text.* "%>
<%
String theMode = request.getParameter("mode");
if( theMode == null)
theMode="";
String serAddr = request.getServerName();
int serPort = request.getServerPort();
String pageTitle = request.getParameter("pagetitle");
%>
<%
if( theMode.equals("submit") )
{
try{
String OWNER_NAME = "";
String DEPARTMENT = " ";
String ID = "";
String ADDRESS = "";
String STATE = "";
String PURPOSE = "";
String browser = "";
String respReqd = "";

OWNER_NAME = request.getParameter("OWNER_NAME");
DEPARTMENT = request.getParameter("DEPARTMENT");
ID= request.getParameter("ID");
ADDRESS =request.getParameter("ADDRESS");
STATE = request.getParameter("STATE");
PURPOSE = request.getParameter("PURPOSE");
browser = request.getParameter("browser");
respReqd = request.getParameter("response");

out.print("The input info: Owner Name: " + OWNER_NAME+
       "DEPARTMENT: " + DEPARTMENT +
           "ID: " + ID + "ADDRESS: " + ADDRESS +
       "STATE: " + STATE + "PURPOSE: " +
       "PURPOSE: " + PURPOSE );
}
catch(Exception ex) {
out.print("<h3>Error encountered in your feedback</h3>");
out.print("Error Message :" + ex);
}
}
%>

<SCRIPT LANGUAGE=JAVASCRIPT>
function validateQuery()
{

}
function validate()
{
if(document.Site.elements['OWNER_NAME'].value == '')
{
alert("Name cannot be null");
document.Site.elements['OWNER_NAME'].focus();
return false;
}

if(document.Site.elements['DEPARTMENT'].value == '')
{
alert("DEPARTMENT cannot be null");
document.Site.elements['DEPARTMENT'].focus();
return false;
}

if(document.Site.elements['ID'].value == '')
{
alert("ID cannot be null");
document.Site.elements['ID'].focus();
return false;
}

if(document.Site.elements['ADDRESS'].value == '')
{
alert('ADDRESS cannot be null.');
document.Site.elements['ADDRESS'].focus();
return false;
}

if(document.Site.elements['STATE'].value == '')
{
alert('STATE cannot be null.');
document.Site.elements['STATE'].focus();
return false;
}

if(document.Site.elements['PURPOSE'].value == '')
{
alert('PURPOSE cannot be null.');
document.Site.elements['PURPOSE'].focus();
return false;
}
}
</SCRIPT>


<HTML>
<HEAD>
<TITLE>Form</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META HTTP-EQUIV="Expires" CONTENT="0">
</HEAD>
<BODY leftmargin="0" rightmargin="0" topmargin="0" marginheight="0" marginwidth="0" class="PageBg">
<form name="Site" onsubmit="return validate()" method=post>
<INPUT type=hidden value=submit name=mode>
<INPUT type=hidden value=null name=pagetitle>
<INPUT type=hidden value=" " name=browser>
<INPUT type=hidden value=N name=response> <INPUT type=hidden name=hidArray>
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="4" WIDTH="100%">
<TR><TD><TABLE BORDER="0" WIDTH="100%" CELLPADDING="0" CELLSPACING="0" class="RegionNoBorder">
<TR><TD class="RegionHeaderColor" WIDTH="100%">
<BR>
<div align="center" class="H2">Request Website
</div>
</BR>
</tr></td>
<TR><TD>
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0"><TR></TR>
<TR><TD>
Name</TD>
<TD><INPUT TYPE="text" NAME="OWNER_NAME" SIZE="15" MAXLENGTH="200">
</TD></TR><TR><TD>Department
</TD><TD><INPUT TYPE="text" NAME="DEPARTMENT" SIZE="15" MAXLENGTH="200">
</TD></TR><TR><TD>
<TR><TD>ID</TD>
<TD><INPUT TYPE="text" NAME="ID" SIZE="15" MAXLENGTH="200"></TD></TR>
<TR><TD>ADDRESS</TD>
<TD><INPUT TYPE="text" NAME="ADDRESS" SIZE="15" MAXLENGTH="100"></TD></TR>
<TR><TD>State</TD>
<TD><INPUT TYPE="text" NAME="STATE" SIZE="12" MAXLENGTH="12"></TD></TR>
<TR><TD>Purpose</TD>
<TD><INPUT TYPE="text" NAME="PURPOSE" SIZE="15" MAXLENGTH="200"></TD></TR>
</TABLE>
</TD></TR>
<TR><TD>
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0"><TR><TD>
</TD><TD>
</TD><TD><INPUT type=submit NAME="Submit" value="Submit"></TD>
<TD></TD>
<TD><INPUT TYPE=button NAME="QUERY_BOTTOM" value="Select Request Site" onClick="validateQuery()" >
</TD></TR>
</table></TD></TR>
</table>
<br></br>

</TABLE>
</FORM>
</body>
</HTML>
 
Old September 4th, 2007, 07:08 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

try using the click() method of the button like after you do the validation try to submit the form using the following line of code.
document.getElementById("formId").submit();

make sure that you add the id atribute for the form tag.


- Rakesh





Similar Threads
Thread Thread Starter Forum Replies Last Post
single submit to related tables forumuser BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 10 December 2nd, 2007 10:29 AM
How to submit the different data on single submit pushpa Classic ASP Databases 1 January 24th, 2007 07:10 PM
submit button shows the user input in another page debjanib ASP.NET 1.0 and 1.1 Professional 3 June 30th, 2006 09:40 AM
Make a image button as default submit button toshi ASP.NET 1.0 and 1.1 Basics 1 June 1st, 2006 05:25 AM
Why my jsp page is submit twice? Edward King Pro JSP 0 November 5th, 2004 04:33 AM





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