PDA

View Full Version : Any suggestions on why this creates an error?


jim_denney
03-14-2003, 04:05 PM
I am creating a function that loops through the form elements and sets flags based on values in specific elements. I have placed alerts before and after every if statement, and the alerts report the values I expect to be there. It only locates those controls named TbxEvType 1, TbxEvType2, etc. and puts their values into the variable tmp_var. But when I take out the alerts, I just get an "Error on page" message. I have gone over this code for hours, any suggestions on what I am doing wrong?

<script type='text/javascript'>
function chk_reg(){
var f = document.frmRegister;
var nc = f.length;
var cntr = 0;
var tmp_val;
var fldname = "TbxEv"
var i = 0;
var lfr = "N";
var lpr = "N";

// First, go through everything and determine if anything is
// checked that indicates full reg or part reg.
for (i = 0; i < nc; i++) {
fldname = f.elements[i].name;
if (String(fldname).substring(0, 5) == "TbxEv") {
cntr = String(fldname).substring(9)
tmp_val = eval("f.TbxEvType" + cntr + ".value");
if (tmp_val == "FR"){
lfr="Y"
}
if (tmp_val == "PR"){
lpr="Y"
}
}
}
}
</script>

Skyzyx
03-14-2003, 04:09 PM
Could you also post the HTML... at least for the form? There might be something in there...

jim_denney
03-14-2003, 04:33 PM
Here is the code, it is pretty lengthy. Everything works fine except for the Chk_Conv function. I cleaned it up some, it is an ASP page that creates all of the form elements from a database.

<HTML>
<HEAD>
<TITLE>Community Bankers of Illinois</TITLE>
<LINK REL=StyleSheet TYPE="text/css" HREF="madchik.css" MEDIA=screen>

<script type='text/javascript'>
function formatNumber(n, p) {

var d, i, m, t;

// check arguments
if (isNaN(n) || isNaN(p) || p != Math.round(p) || p < 0)
return "Error";

// if zero decimal places was specified, just round the number
if (p == 0)
return Math.round(n).toString();

// otherwise, round to the given number of decimal places
m = Math.pow(10, p);
t = Math.round(n * m) / m;
t = t.toString();

// determine how many zeros need to be added after the decimal point
if (t.indexOf(".") < 0)
t += ".";
d = t.length - 1 - t.indexOf(".");

// add the trailing zeros
for (i = 0; i < p - d; i++)
t += "0";

return(t);
}
</script>

<script type='text/javascript'>

if (!document.layers&&!document.all&&!document.getElementById)

function showtip(current,e,text){

if (document.all||document.getElementById){
thetitle=text.split('<br>')
if (thetitle.length>1){
thetitles=''
for (i=0;i<thetitle.length;i++)
thetitles+=thetitle[i]
current.title=thetitles
}
else
current.title=text
}
else if (document.layers){
document.tooltip.document.write('<layer bgColor="white" style="border:1px solid black;font-size:12px;">'+text+'</layer>')
document.tooltip.document.close()
document.tooltip.left=e.pageX+5
document.tooltip.top=e.pageY+5
document.tooltip.visibility="show"
}
}

function hidetip(){
if (document.layers)
document.tooltip.visibility="hidden"
}
</script>

<script type='text/javascript'>

</script>

<script type='text/javascript'>
function chk_reg(){
var f = document.frmRegister;
var nc = f.length;
var cntr = 0;
var tmp_val;
var fldname = "Chk;"
var i = 0;
var l_fr = "N";
var l_pr = "N";

// First, go through everything and determine if anything is checked that indicates full reg or
// part reg. If so, zero out costs for events that are included in full/part registrations.
for (i = 0; i < nc; i++) {
fldname = f.elements[i].name;
if (String(fldname).substring(0, 5) == "TbxEv") {
cntr = String(fldname).substring(9)
tmp_val = eval("f.TbxEvType" + cntr + ".value");
if (tmp_val == "FR"){
l_fr="Y"
}
if (tmp_val == "PR"){
l_pr="Y"
}
}
}
}
</script>

<body>
<form name="frmRegister" action="Register_Conv.asp" method="POST" >

<font class='PgHdr'>CBAIs 29th Annual Convention</font><br>
<input type = "hidden" name="TbxConvCode" value="HAVT">
<input type = "hidden" name="TbxMbrCode" value="168CT">
<input type="hidden" name="TbxStartDate" size = "10" Value = "09/15/2003">
<input type="hidden" name="TbxPreRegEnds" size = "10" Value = "08/31/2003">
<input type="hidden" name="TbxStdRegEnds" size = "10" Value = "09/15/2003">
<input type="hidden" name="TbxRegType" size = "10" Value = "Pre-Reg">

<table>
<tr><td>
<table>
<tr><td class="label">First Name:</td>
<td><input type="text" name="TbxFirstName" size = "20" Value = ""></td></tr>

<tr><td class="Label">Last Name:</td>
<td><input type="text" name="TbxLastName" size = "20" Value = ""></td></tr>

<tr><td class="Label">Title:</td>
<td><input type="text" name="TbxTitle" size = "20" Value = ""></td></tr>

<tr><td class="Label">Name for Badge:</td>
<td><input type="text" name="TbxBadgeName" size = "20" Value = ""></td></tr>

<tr><td><font class="Label">Handicap </font><font size=-2>(for Golf Outing)</font>):</font></font></td>
<td><input type="text" name="TbxHandiCap" size = "20" Value = ""></td></tr>
</td>
</table>
<td class="Title" valign="top">Full Registration includes Welcoming Reception, Opening Breakfast, Business Meeting Luncheon, and Saturday Dinner/Dance.</td></tr>
</table>
<input type="hidden" name="TbxMbrRegKey" size = "20" Value = "974">
<!-- <font face="Verdana, Arial, Helvetica, sans-serif" size = 3 color="blue" weight=800> -->
<span class="Title">
You qualify for pre-registration.</span>
<Table Border='1'>
<tr><td>Attend</td><td>Cost</td></tr>
<tr><td><input type='checkbox' name='ChkEvent1' checked='checked' onclick='chk_reg()'
onmouseover='showtip(this,event,"Full registration includes Welcoming Reception (Thursday),
Opening Breakfast (Friday), Business Meeting Luncheon (Friday) and Dinner/Dance (Saturday).")'
onmouseout="hidetip()">Full Registration</td>

<td align='right'><input type='text' name='TbxCost1'size = '10' value='299.00' onFocus='blur()'
style='text-align: right' ><input type='hidden' name='TbxHCost' value='299.00'>
<input type='hidden' name='TbxID1' size = '10' value='443'></td>

<td><input type='text' name='TbxEvType1' size = '4' value='FR'></td></tr>

<tr><td>&nbsp;&nbsp;&nbsp;<input type='checkbox' name='ChkEvent2' onclick='chk_reg()'
onmouseover='showtip(this,event,"Relax, hang out with friends, sip wine and snack on crackers and cheese.")'
onmouseout="hidetip()">Welcoming Reception</td>
<td align='right'><input type='text' name='TbxCost2'size = '10' value='0' onFocus='blur()'
style='text-align: right' ><input type='hidden' name='TbxHCost' value='0'>
<input type='hidden' name='TbxID2' size = '10' value='482'></td>
<td><input type='text' name='TbxEvType2' size = '4' value='IFR'></td></tr>

<tr><td>&nbsp;&nbsp;&nbsp;<input type='checkbox' name='ChkEvent3' onclick='chk_reg()'
onmouseover='showtip(this,event,"Bacon and eggs for the young-at-heart, cereal and fruit for the health concious.")'
onmouseout="hidetip()">Opening Breakfast</td>
<td align='right'><input type='text' name='TbxCost3'size = '10' value='0' onFocus='blur()' style='text-align: right' ><input type='hidden' name='TbxHCost' value='0'>
<input type='hidden' name='TbxID3' size = '10' value='486'></td>
<td><input type='text' name='TbxEvType3' size = '4' value='IFR'></td></tr>

<tr><td>&nbsp;&nbsp;&nbsp;<input type='checkbox' name='ChkEvent4' onclick='chk_reg()'
onmouseover='showtip(this,event,"The Sangamo Club is located at 211 East Adams in historic downtown Springfield.")'
onmouseout="hidetip()">Partners Program Thursday: Sangamo Club </td>
<td align='right'><input type='text' name='TbxCost4'size = '10' value='0' onFocus='blur()' style='text-align: right' ><input type='hidden' name='TbxHCost' value='0'>
<input type='hidden' name='TbxID4' size = '10' value='502'></td>
<td><input type='text' name='TbxEvType4' size = '4' value='IFR'></td></tr>

<tr><td>&nbsp;&nbsp;&nbsp;<input type='checkbox' name='ChkEvent5' onclick='chk_reg()'
onmouseover='showtip(this,event,"Relax at the Illini Country Club. Or spend the day golfing, playing tennis or participating in any of the other activities available upon request.")'
onmouseout="hidetip()">Partners Program Friday: The Illini C.C.</td>
<td align='right'><input type='text' name='TbxCost5'size = '10' value='0' onFocus='blur()' style='text-align: right' ><input type='hidden' name='TbxHCost' value='0'>
<input type='hidden' name='TbxID5' size = '10' value='506'></td>
<td><input type='text' name='TbxEvType5' size = '4' value='IFR'></td></tr>

<tr><td>&nbsp;&nbsp;&nbsp;<input type='checkbox' name='ChkEvent6' onclick='chk_reg()'
onmouseover='showtip(this,event,"Dinner followed by dance.")' onmouseout="hidetip()">Saturday Evening Dinner and Dance </td>
<td align='right'><input type='text' name='TbxCost6'size = '10' value='0' onFocus='blur()' style='text-align: right' ><input type='hidden' name='TbxHCost' value='0'>
<input type='hidden' name='TbxID6' size = '10' value='494'></td>
<td><input type='text' name='TbxEvType6' size = '4' value='IFR'></td></tr>

<tr><td><input type='checkbox' name='ChkEvent7' onclick='chk_reg()'
onmouseover='showtip(this,event,"Golf with friends and partners. ")'
onmouseout="hidetip()">Golf Outing (Thursday) </td>
<td align='right'><input type='text' name='TbxCost7'size = '10' value='89.00' onFocus='blur()' style='text-align: right' ><input type='hidden' name='TbxHCost' value='89.00'>
<input type='hidden' name='TbxID7' size = '10' value='478'></td>
<td><input type='text' name='TbxEvType7' size = '4' value='XTRA'></td></tr>

<tr><td><input type='checkbox' name='ChkEvent8' onclick='chk_reg()'
onmouseover='showtip(this,event,"Two step to the tunes of Jerry Reed.")'
onmouseout="hidetip()">Western Wingding with Jerry Reed </td>
<td align='right'><input type='text' name='TbxCost8'size = '10' value='95.00' onFocus='blur()' style='text-align: right' ><input type='hidden' name='TbxHCost' value='95.00'>
<input type='hidden' name='TbxID8' size = '10' value='498'></td>
<td><input type='text' name='TbxEvType8' size = '4' value='XTRA'></td></tr>

<tr><td>Cost for selected events:</td><td><input type='Text' name='TbxTtlCost' size = '10' Value = '299.00' onFocus='blur()' style='text-align: right' ></td></tr></TABLE><input type='hidden' name='TbxEventString' Value = '443'>

<input type="submit" name="CmdSubmit" value="Enter Another Attendee">
<input type="button" value="Proceed To Checkout" onclick="document.frmRegister.action='verify_conv.asp';document.frmRegister.submit()">
<br>

</form>

<hr width = 640>
</BODY></HTML>