Click to See Complete Forum and Search --> : a question about script tag position


awakejames
May 18th, 2004, 04:01 AM
hi friends
this is a jsp for download depand users input. the jsp invoke itself to get parameters from this page. i write a javascript code to validate the input field.


<!--
it is a page to set period time to be a download condition.
page name is selectoption.jsp
-->
<%@ page pageEncoding="GB2312"%>
<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@ taglib uri="/WEB-INF/tlds/filedownload.tld" prefix="download"%>
<%
//set parameter values for download tag
String startTime = request.getParameter("starttime");
String endTime = request.getParameter("endtime");
String type = request.getParameter("type");
if(startTime==null)startTime="";
if(endTime==null)endTime="";
if(type==null)type="";
String mainSQL = "SELECT userinfo.userid, userinfo.esource AS EDMsource, userinfo.regcode, userinfo.username, userinfo.password,regmode.ename AS regmode, regmode.cname AS registemode, regmode.datedesc,regmode.feedesc, status.ename AS statusename, status.cname AS statuscname, userinfo.badgeid, userinfo.lastname,userinfo.firstname, userinfo.companyname, userinfo.email, userinfo.title, jobfunction.ename AS jobfunctionename, jobfunction.cname AS jobfunctioncname, userinfo.telprefix, userinfo.tel, userinfo.faxprefix, userinfo.fax, userinfo.mobile, userinfo.comaddr, userinfo.country, area.ename AS areaename, area.cname AS areacname, userinfo.postalcode, industry.ename AS industryename, industry.cname AS industrycname, userinfo.otherindustry, organisation.ename AS organisationename, organisation.cname AS organisationcname, userinfo.otherorganisation, companysize.ename AS companysizeename, companysize.cname AS companysizecname, purchaserole.ename AS purchaseroleename, purchaserole.cname AS purchaserolecname, userinfo.regdate AS registedate, userinfo.paydate, userinfo.fee FROM userinfo LEFT OUTER JOIN purchaserole ON userinfo.purchaseroleid = purchaserole.purchaseid LEFT OUTER JOIN organisation ON userinfo.organisationid = organisation.organisationid LEFT OUTER JOIN companysize ON userinfo.companysizeid = companysize.companysizeid LEFT OUTER JOIN area ON userinfo.areaid = area.areaid LEFT OUTER JOIN industry ON userinfo.industryid = industry.industryid LEFT OUTER JOIN status ON userinfo.statusid = status.statusid LEFT OUTER JOIN jobfunction ON userinfo.jobfunctionid = jobfunction.jobid LEFT OUTER JOIN regmode ON userinfo.regmodeid = regmode.regmodeid ";
%>
<!DOCTYPE HTML PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>download</title>
</head>
<body>
<DIV id=popCal onclick=event.cancelBubble=true
style="BORDER-BOTTOM: 2px ridge; BORDER-LEFT: 2px ridge; BORDER-RIGHT: 2px ridge; BORDER-TOP: 2px ridge; POSITION: absolute; VISIBILITY: hidden; WIDTH: 10px; Z-INDEX: 100">
<IFRAME frameBorder=0 height=188 name=popFrame scrolling=no src="../util/popcjs.htm"
width=183>
</IFRAME>
</DIV>
<SCRIPT event=onclick() for=document>
popCal.style.visibility = "hidden";
</SCRIPT>

<form name="downloadform" method="post" action = "/ms/DATA/selectoption.jsp" onsubmit="javascript:checkinput()">
<TABLE width="100%" border=1 cellPadding=2 cellSpacing=0
borderColorLight=#D6D6E6 borderColorDark=#ffffff>
<TBODY>
<TR vAlign=bottom bgColor=#e9e9d1>
<TD bgcolor="#D6D6E6"><strong>download</strong></TD>
</TR>
</TBODY>
</TABLE>
<table>
<tr>
<td>
select a kind of person
</td>
<td>
<select name="type">
<!--set the type option's values, and store the selected values on the page-->
<option value="1" <%if("1".equals(request.getParameter("type"))){%>selected<%}%>>normal</option>
<option value="2" <%if("2".equals(request.getParameter("type"))){%>selected<%}%>>free</option>
<option value="3" <%if("3".equals(request.getParameter("type"))){%>selected<%}%>>other</option>
</select>
</td>
<td>
start of time
</td>
<td nowrap>
<input name="starttime" type="text" size="12" value=<%if(request.getParameter("starttime")==null){%>""<%}else{%><%=request.getParameter("starttime")%><%}%>>
<input name="button" type=button onClick="popFrame.fPopCalendar(starttime,starttime,popCal);return false" value=V>
</td>
<td>
end of time
</td>
<td nowrap>
<input name="endtime" type="text" size="12" value=<%if(request.getParameter("endtime")==null){%>""<%}else{%><%=request.getParameter("endtime")%><%}%>>
<input name="button" type=button onClick="popFrame.fPopCalendar(endtime,endtime,popCal);return false" value=V>
</td>
<td>
<a href="/ms/DATA/downloadoption.jsp">
</td>
<td>
<!-- it is a tag for getting parameters to query database and download the result of query to be a excel file-->
<A id="downloadlink" href="<download:downloadfileurl locale='<%=java.util.Locale.CHINA%>'
provider="cn.com.actop.sunnetwork.bean.NormalPersonInfo"
hanlder="cn.com.actop.download.ExcelFileHanlder">
<download:param name="filename" value='<%= "StaUserInfo.xls" %>'/>
<download:param name="starttime" value='<%=startTime%>'/>
<download:param name="endtime" value='<%=endTime%>'/>
<download:param name="type" value='<%=type%>'/>
<download:param name="mainsql" value='<%=mainSQL%>'/>
</download:downloadfileurl>
">
</A>
</td>
<td>
<input type="submit" name="submit" value="click to download">
</td>
</tr>
</table>
</form>
<div id="waiting" style="position:absolute; top:100; left:20; z-index:10; visibility:hidden"><TABLE WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=0><TR><td width=30%></td><TD bgcolor=#8dbae8><TABLE WIDTH=100% height=50 BORDER=0 CELLSPACING=2 CELLPADDING=0><TR><td bgcolor="#f7fbfe" align=center><font color="#000099">数据量大,传输转换时间长,请耐心等候,最好不要进行其他操作...</font></td></tr></table></td><td width=30%></td></tr></table></div></div>
<!--the script is for invoking the download tag-->
<script language="javascript">
if(downloadform.starttime.value!=""&&downloadform.endtime.value!="")
downloadlink.click();
</script>

</body>
</html>
<!-- validate two input field-->
<script language="javascript">
function checkinput(){
if(document.downloadform.starttime.value==''){
alert("请输入开始日期");
return false;
}
if(document.downloadform.endtime.value==''){
alert("请输入结束日期");
return false;
}
return confirm('您确定要提交吗?');
}
</script>


My question is when i run this page ,at first click download button,i can get the excel file that name is StaUserInfo.xls.but when i click download button continue, a error alert will appear on the page.the error alert content is 'error:lose object' .the error position point to the onsubmit().so i think the problem must be related with script tag of checkinput(). then i chang the position of the script tag of checkinput() into body section,unuseless.only when i move the script tage into head section ,it runs correctly.
i cannot understand the use of position javascript tag completely.
i hope i can share friends thinking about this porblem.