PDA

View Full Version : Function not being Called


anand74
04-07-2004, 05:37 AM
hello

I know it is alot to go through , but please check why my div tag does not hide when the input value is 2

Thanks in advance

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

<head><TITLE>POST OFFICE BOX RENEWALS</TITLE>
<META http-equiv=Content-Type content="text/html; charset=unicode">
<LINK href= "../postyle.css" type= text/css rel= stylesheet>

<%

dim adoCon, strSQLType,strSQLTitle,strSQLCDate, LoadUDL,RSTitle, RSBType,strSQLAmount,RSAmount
dim selBType,selDes
selBType=Request.form("selBType")
selDes=Request.form("selDes")

loadUDL = "File Name=C:\renewal\box.UDL;"
'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open loadUDL

strSQLType = " SELECT BOX_TYPE_CODE || ' - ' || BOX_TYPE_DESC BOX_TYPE_DESC, BOX_TYPE_CODE FROM BOX_TYPE"
strSQLCDate ="SELECT YEAR FROM LAST_MONTH"
strSQLTitle = " SELECT * FROM TITLE "

set RSBType= adoCon.execute(strSQLType)
set RSCDate= adoCon.execute(strSQLCDate)
set RSTitle= adoCon.execute(strSQLTitle)


strSQLDesc = " select "
strSQLDesc = strSQLDesc & " description, "
strSQLDesc = strSQLDesc & " amount "
strSQLDesc= strSQLDesc & " from "
strSQLDesc= strSQLDesc & " box_amount"
strSQLDesc= strSQLDesc & " where"
strSQLDesc= strSQLDesc & " box_type_code = '" & selBType & "' and"
strSQLDesc= strSQLDesc & " to_number(to_char(sysdate, 'MM')) "
strSQLDesc= strSQLDesc & " between start_period and end_period"
set RSDescrip=adoCon.execute(strSQLDesc)

strSQLAmount = " select "
strSQLAmount = strSQLAmount & " amount "
strSQLAmount= strSQLAmount & " from "
strSQLAmount= strSQLAmount & " box_amount"
strSQLAmount= strSQLAmount & " where"
strSQLAmount= strSQLAmount & " box_type_code = '" & selBType & "' and"
strSQLAmount= strSQLAmount & " description = '" & selDes & "' and"
strSQLAmount= strSQLAmount & " to_number(to_char(sysdate, 'MM')) "
strSQLAmount= strSQLAmount & " between start_period and end_period"
set RSAmount= adoCon.execute(strSQLAmount)

Dim actAmount
if not rsAmount.eof then
actAmount = rsAmount(0)
else
actAmount = 0
end if
%>
<%
if selBType=2 then %>
<script language=JavaScript>
{
showBusiness()
}
</script>

<%else%>

<script language=JavaScript>
{
hideBusiness()
}
</script>

<%end if






%>

<script language=JavaScript script type="text/javascript">
function showBusiness()
{
divB.style.visibility ="visible";
}

function hideBusiness()
{
divB.style.visibility ="hidden";
}

function rePost()
{
rform.action = "newpo_sapriv_individ.asp";
document.rform.submit();
}
</script>

</head>


<BODY onload=cmdFocus() >
<!--#include file="../include/ValidateID.asp"-->
<form name=rform action="savedetails.asp" method=post>
<table border="0" width="100%" cellspacing="0" cellpadding="0" >
<tr><th colspan=4><font color="yellow"><b> New Post Office Box/Bag Rental By </b></font></th></tr>
<tr><th colspan=4><font color="yellow"><b> Private/Foreign Individual and Business</b></font></th></tr>
<tr >

<td align="right" width="40%" ><b>PO Box/Bag Number :</b></td>
<td width="10%"><INPUT id=txtnBnum name=txtnBnum size="5"></td>
<td align="right" width="40%"><b> Phone Area Code(w):</b> </td>
<td width="10%"><INPUT id=txtnDcodeW name=txtnDcodeW size="2"></td>
</tr>
<tr>
<td align="right" width="40%"><b>PO Box/Bag Collection Point:</b></td>
<td width="10%"><INPUT id=txtBcoll name=txtnBcoll size="5"></td>
<td align="right" width="40%"><b>Work Phone Number:</b></td>
<td width="10%"><INPUT id=txtnTelW name=txtnTelW size="8"></td>
</tr>
<tr>
<td align="right" width="40%"><b>PO Box/Bag Post Code:</b></td>
<td width="10%"><INPUT id=txtPcode name=txtnPcode size="5"></td>
<td align="right" width="40%"><b>Cell Phone Number:</b></td>
<td width="10%"><INPUT id=txtnCell name=txtnCell size="8"></td>
</tr>
<tr>
<td align="right" width="40%"><b>PO Box/Bag Type:</b></td>
<td width="10%" ><SELECT id=selBType onchange="rePost()" name=selBType style="HEIGHT: 30px; WIDTH: 180px">
<option value="">PLEASE SELECT AN OPTION </option>
<%
Do While Not(RSBType.EOF)

%>
<OPTION value="<%=RSBType("BOX_TYPE_CODE")%>" <% if instr(selBType,RSBType("BOX_TYPE_CODE")) then %> selected <% end if %> ><%=RSBType("BOX_TYPE_DESC")%></OPTION>
<%
RSBType.MoveNext
Loop
%>

</SELECT></td>
<td align="right" width="40%"><b>e-Mail :</b></td>
<td width="10%"><INPUT id=txtsEmail name=txtsEmail ></td>
</tr>
<tr>
<td align="right" width="50%"><b>Description:</b></td>
<td width="10%"><SELECT id=selDes name=selDes onchange="rePost()" style="HEIGHT: 30px; WIDTH: 180px">
<option value="">PLEASE SELECT AN OPTION </option>
<%
Do While Not(RSDescrip.EOF)
%>
<OPTION value="<%=RSDescrip("DESCRIPTION")%>"<% if instr(selDes,RSDescrip("DESCRIPTION")) then %> selected <% end if %> ><%=RSDescrip("DESCRIPTION")%></OPTION>
<%
RSDescrip.MoveNext
Loop
%>

</SELECT></td>
<td align="right" width="40%"><b>Street Address Line 1:</b></B></td>
<td width="10%"><INPUT id=txtsAdd1 name=txtsAdd1 ></td>
</tr>
<tr>
<td align="right" width="40%"><b>Amount for Box/Bag:</b></td>
<td align="center" width="10%" bgcolor="white"><b><font color="navy">R<%=formatNumber(actAmount ,2)%></b></label> </td>
<td align="right" width="40%"><b>Street Address Line 2:</b></td>
<td width="10%"><INPUT id=txtsAdd2 name=txtsAdd2 ></td>
</tr>
<tr>
<td align="right" width="40%"><b>Title:</b></td>
<td width="10%"><SELECT id=selTitle name=selTitle style="HEIGHT: 30px; WIDTH: 112px">
<%
Do While Not(RSTitle.EOF)
%>
<OPTION value="<%=RSTitle("TITLE_CODE")%>" ><%=RSTitle("TITLE_CODE")%></OPTION>
<%
RSTitle.MoveNext
Loop
%>
</SELECT>
</td>
<td align="right" width="40%"><b>Street Address Line 3:</b></td>
<td width="10%"><INPUT id=txtsAdd3 name=txtsAdd3 ></td>
</tr>
<tr>
<td align="right" width="40%"><b>Initials:</b></td>
<td width="10%"><INPUT id=txtsInitial name=txtsInitial size="1"></td>
<td align="right" width="40%"><b>Suburb:</b></td>
<td width="10%"><INPUT id=txtsSurburb
name=txtsSurburb></td>
</tr>
<tr>
<td align="right" width="40%"><b>Surname:</b></td>
<td width="10%" colspan=2><INPUT id=txtsSurname name=txtsSurname style="HEIGHT: 22px; WIDTH: 177px" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<b>Town/City:</b></td>
<td width="10%"><INPUT id=txtsTown name=txtsTown ></td>
</tr>
<tr>
<td align="right" width="40%">
<b>ID No : </b>
<input type="radio" checked name="optIdPass" value="0" >
<b>Passport No:</b>
<INPUT type=radio value="1" name="optIDPass" >
</td>
<td width="10%" ><INPUT id=txtnID name=txtnID size="11" maxlength=13></td>
<td width="40%" align="right"><b>Post Code:</b></td>
<td width="10%"><INPUT id=txtnPostcode
name=txtnPostcode size="2"></td>
</tr>
<tr>
<td align="right" width="40%"><b>Telephone Area Code(H):</b></td>
<td width="10%"><INPUT id=txtnDcodeH name=txtnDcodeH size="2"></td>
<td align="right" width="40%"><b>Telephone Number(H):</b></td>
<td width="10%"><INPUT id=txtnTelH name=txtnTelH
size="8"></td>
</tr>
<tr><td colspan=4>
<div id="divB" >
<table border="0" width="100%" cellspacing="0" cellpadding="0" bgcolor="#cococ0" >
<tr >
<td align="right" width="20%"><font color="black"><b>Name of Business:</b></td>
<td align="middle" width="30%"><INPUT id=BuName name=BuName size="20"></td>
<td align="right" width="20%"><font color="black"><b>Fax Code:</b></td>
<td align="middle" width="30%"><INPUT id=txtnFaxCode name=txtnFaxCode size="2"></td>
</tr>
<tr>
<td align="right" width="20%"><font color="black"><b>Business Reg Number:</b></td>
<td align="middle" width="30%"><INPUT id=txtRegNum name=txtRegNum size="20"></td>
<td align="right" width="20%"><font color="black"><b>Fax Number:</b></td>
<td align="middle" width="30%"><INPUT id=txtnFaxNo name=txtnFaxNo size="10"></td>
</tr>
</table>
</div>
</td></tr>

<table border="0" width="100%" cellspacing="0" cellpadding="0" bordercolor="red" >
<tr>
<td align="right" colspan=4><b><b><input type="submit" value="Submit" name="B1" onclick=cmdCheckInputs() style="COLOR: #ff0000; FONT-WEIGHT: bold" >
<input type="reset" value="Reset" name="B2" onclick=cmdclear() style="COLOR: #ff0000; FONT-WEIGHT: bold" ></b></b>
</td>
</tr>
</table>

</table>

</form>

<script language=Javascript script type="text/javascript" >

divB.style.visibility="hidden";

</script>

</BODY>
</html>

agent002
04-07-2004, 09:02 AM
Ok, first off, remove this from the bottom of the page:
<script language=Javascript script type="text/javascript" >

divB.style.visibility="hidden";

</script>
And instead of showBusiness() (and hideBusiness()), use
window.open = showBusiness;
(and hideBusiness). You are calling the JavaScript before either the functions, showBusiness() or hideBusiness(), or the actual document body content has loaded. If calling the function at window.onload, it is called when everything has loaded and will hence work fine.

Also, your script will only work in IE and Opera unless you change divB.style.visibility to
document.getElementById('divB').style.visibility
:)

Vincent Puglia
04-07-2004, 09:38 AM
Hi agent002,

I really don't think s/he's concerned with any browser other than IE since that's asp in the code.

Since I'm not especially conversant with snakes (asps), I can't speak with authority, but...

I'm assuming this line:

selBType=Request.form("selBType")

is setting the value on the server

and that these lines are coming up as problems because my system doesn't recognize asp:

...
<%
if selBType=2 then %>
<script language=JavaScript>
{
showBusiness()
}
</script>
<%else%>
...


although I do wonder if they shouldn't be written out as:


...
<%
if selBType=2 then
Response.write("<script language=JavaScript>
{
showBusiness()
}
</script>")
%>
<%else%>
...


or whatever it is you aspers do to echo.

Vinny

anand74
04-07-2004, 10:03 AM
The reasson why I attached that at the bottom of the page is that when the page loads the table within the div tag hides and only when the user selects option 2 with value 2 then the table will show.

I did manage with the code i currently have to hide the table onload , but it does not show when it gets value 2.

thanks