Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Frustration..Check this out 1

Status
Not open for further replies.

RhythmAddict112

Programmer
Jun 17, 2004
625
US
Hey everyone whats up...I have a page that has been working fine ever since I can remember...The full source is below.....I get a error stating:
"'line 11 elements[...].value' is null or not an object"

Do you get the same msg?? How can i resolve this? I'm kind of baffled since its been workin for months!

[code

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="Style/style.css">
<SCRIPT>
function validateForm( frm )
{
for ( var row = 1; row <= 51; ++row )
{
var kits = parseInt( frm.elements["kits"+row].value );
if ( ! isNaN(kits) && kits > 0 )
{
// kits in this row is a number more than zero...
// so check for all other fields...
var name = frm.elements["row"+row+"col1"].value;
if ( name.length < 1 ) // choose a minimum length
{
alert("Please Provide company name in row " + row);
return false;
}

var cust = frm.elements["cust_name"+row].value;
if ( cust.length < 3 ) //min length of 3
{
alert("Please provide customer name in row " + row);
return false;
}

var address = frm.elements["row"+row+"col2"].value;
if ( address.length < 3 )
{
alert("Please provide address in row "+row)
return false;
}

var city = frm.elements["row"+row+"col3"].value;
if ( city.length < 3 )
{
alert("Please enter valid value for city field in row "+row)
return false;
}

var stat = frm.elements["row"+row+"col4"].value;
if ( stat.length < 2 )
{
alert("Please correct state field in row "+row)
return false;
}

var zip = frm.elements["row"+row+"col5"].value;
if ( zip.length < 5 )
{
alert("Please correct zip code on row"+row)
return false;
}

var mam = frm.elements["row"+row+"col6"].value;
if ( mam.length < 1 )
{
alert("Please provide MAM field on row "+row)
return false;
}


} // end of "if kits for this row is > 0"
} // end of loop on all rows
// if no errors, then:
return true;

} // end of function
</script>
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Nannette Thacker -->
<!-- -->
<!-- Begin
function checkNumeric(objName,minval, maxval,comma,period,hyphen)
{
var numberfield = objName;
if (chkNumeric(objName,minval,maxval,comma,period,hyphen) == false)
{
numberfield.select();
numberfield.focus();
return false;
}
else
{
return true;
}
}

function chkNumeric(objName,minval,maxval,comma,period,hyphen)
{
// only allow 0-9 be entered, plus any values passed
// (can be in any order, and don't have to be comma, period, or hyphen)
// if all numbers allow commas, periods, hyphens or whatever,
// just hard code it here and take out the passed parameters
var checkOK = "0123456789" + comma + period + hyphen;
var checkStr = objName;
var allValid = true;
var decPoints = 0;
var allNum = "";

for (i = 0; i < checkStr.value.length; i++)
{
ch = checkStr.value.charAt(i);
for (j = 0; j < checkOK.length; j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
if (ch != ",")
allNum += ch;
}
if (!allValid)
{
alertsay = "Please enter only these values \""
alertsay = alertsay + checkOK + "\" in the \"" + checkStr.name + "\" field."
alert(alertsay);
return (false);
}

// set the minimum and maximum
var chkVal = allNum;
var prsVal = parseInt(allNum);
if (chkVal != "" && !(prsVal >= minval && prsVal <= maxval))
{
alertsay = "Please enter a value greater than or "
alertsay = alertsay + "equal to \"" + minval + "\" and less than or "
alertsay = alertsay + "equal to \"" + maxval + "\" in the \"" + checkStr.name + "\" field."
alert(alertsay);
return (false);
}
}
// End -->
</script>



<script language="JavaScript">
function copyrow(copyToRow,columnCount) {
for (i=1; i<=columnCount ; i++) {
document.myform.elements['row' + copyToRow + 'col' + i].value = document.myform.elements['row' +

(copyToRow-1) + 'col' + i].value;
}
}
</script>
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Ryan A. Somma (ryan@waygate.com) -->
<!-- Web Site: -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! -->

<!-- Begin
function stringFilter (input) {
s = input.value;
filteredValues = "';`";
var i;
var returnString = "";
for (i = 0; i < s.length; i++) { // Search through string and append to unfiltered values to returnString.
var c = s.charAt(i);
if (filteredValues.indexOf(c) == -1) returnString += c;
}
input.value = returnString;
}
// End -->
</script>
</HEAD>


<body LEFTMARGIN="5" rightmargin="5" TOPMARGIN="5" marginwidth="0" marginheight="0">



<form name="myform" method="post" action="write.asp" onSubmit="return validateForm(this);" >

<table border"4" bordercolor="#000000" align="center" width="90%">
<tr>
<td>&nbsp;

</td>
<td align="right">
<input name="Submit" type="submit" value="Save" class="text" >
</td>
</tr>
</table>
<table border=1 width='90%' align='center' class='norm'><tr><td align='center' class=shadeMed>No.</td><td

align='center' class=shadeMed># of Kits</td><td align='center' class=shadeMed>Region</td><td align='center'

class=shadeMed>Company Name</td><td align='center' class=shadeMed>Customer Name</td><td align='center'

class=shadeMed>Title</td><td align='center' class=shadeMed>Address</td><td align='center'

class=shadeMed>City</td><td align='center' class=shadeMed>State</td><td align='center'

class=shadeMed>Zip</td><td align='center' class=shadeMed>MAM</td><td align='center'

class=shadeMed>Duplicate</td></tr>
<tr>

<td class="ShadeMed" align="center">
1

</td>
<td class="ShadeMed" align="center">
<!-- <input type="button" value="Copy" onclick="copyrow(2,5)">-->
<input name="kits1" type="text" value="0" size="1" maxlength="2" class="text"

onBlur="checkNumeric(this,0,99,'','','');">
</td>
<td class="ShadeMed" align="center">
<input name="region1" type="text" value=NYM size="2" maxlength="2" class="text" disabled>
<input name="region1" type="hidden" value=NYM>
</td>
<td class="ShadeMed" align="center">
<input name="row1col1" type="text" value="" size="15" maxlength="45" class="text"

onBlur="stringFilter(row1col1);">
</td>
<td class="ShadeMed" align="center">
<input name="cust_name1" type="text" value="" size="10" maxlength="45" class="text"

onBlur="stringFilter(cust_name1);">
</td>
<td class="ShadeMed" align="center">
<input name="ttl1" type="text" value="" size="10" maxlength="45" class="text"

onBlur="stringFilter(ttl1);">
</td>
<td class="ShadeMed" align="center">
<input name="row1col2" type="text" value="" size="20" maxlength="65" class="text"

onBlur="stringFilter(row1col2);">
</td>
<td class="ShadeMed" align="center">
<input name="row1col3" type="text" value="" size="10" maxlength="30" class="text"

onBlur="stringFilter(row1col3);">
</td>
<td class="ShadeMed" align="center">
<!--state-->
<input name="row1col4" type="text" value="" size="2" maxlength="2" class="text"

onBlur="stringFilter(row1col4);">

</td>
<td class="ShadeMed" align="center">
<input name="row1col5" type="text" value="" size="5" maxlength="5" class="text"

onBlur="checkNumeric(this,0,99999,'','','');">
</td>
<td class="ShadeMed" align="center">
<input name="row1col6" type="text" value="" size="20" maxlength="30" class="text"

onBlur="stringFilter(row1col6);">
</td>
<td class="ShadeMed" align="center">
<input type="button" value="Copy Row" onclick="copyrow(2,6)" class="text"/>
<input type="hidden" name="batchdate1" value=17-JAN-2005 />
</td>
</tr>





<tr>

<td class="ShadeLite" align="center">
2

</td>
<td class="ShadeLite" align="center">
<!--<input type="button" value="Copy" onclick="copyrow(3,5)">-->
<input name="kits2" type="text" value="0" size="1" maxlength="2" class="text"

onBlur="checkNumeric(this,0,99,'','','');">
</td>
<td class="ShadeLite" align="center">
<input name="region2" type="text" value=NYM size="2" maxlength="2" class="text" disabled>
<input name="region2" type="hidden" value=NYM>
</td>
<td class="ShadeLite" align="center">
<input name="row2col1" type="text" value="" size="15" maxlength="35" class="text"

onBlur="stringFilter(row2col1);">
</td>
<td class="ShadeLite" align="center">
<input name="cust_name2" type="text" value="" size="10" maxlength="25" class="text"

onBlur="stringFilter(cust_name2);">
</td>
<td class="ShadeLite" align="center">
<input name="ttl2" type="text" value="" size="10" maxlength="25" class="text"

onBlur="stringFilter(ttl2);">
</td>
<td class="ShadeLite" align="center">
<input name="row2col2" type="text" value="" size="20" maxlength="75" class="text"

onBlur="stringFilter(row2col2);">
</td>
<td class="ShadeLite" align="center">
<input name="row2col3" type="text" value="" size="10" maxlength="30" class="text"

onBlur="stringFilter(row2col3);">
</td>
<td class="ShadeLite" align="center">
<!--state-->
<input name="row2col4" type="text" value="" size="2" maxlength="2" class="text"

onBlur="stringFilter(row2col4);">

</td>
<td class="ShadeLite" align="center">
<input name="row2col5" type="text" value="" size="5" maxlength="5" class="text"

onBlur="checkNumeric(this,0,99999,'','','');">
</td>
<td class="ShadeLite" align="center">
<input name="row2col6" type="text" value="" size="20" maxlength="30" class="text"

onBlur="stringFilter(row2col6);">
</td>
<td class="ShadeMed" align="center">
<input type="button" value="Copy Row" onclick="copyrow(3,6)" class="text2"/>
<input type="hidden" name="batchdate2" value=17-JAN-2005 />
</td>
</tr>



<p align="right">
<h1>Package Submission - <font size="-1">The current batch is for January</h1></font>
<P style="MARGIN-TOP: 0px">

<hr width="40%" align="LEFT">
<p style="MARGIN-TOP: 0px" align="right">


</form>

</body>
</html>
[/code]

Use your resources, you're on the internet!
 
I take it that you're SURE you have 51 kits, and aren't missing any numbers in the middle. You can always put an alert(row) right before

var kits = parseInt( frm.elements["kits"+row].value );

and see what the last number is before the error. Or you could use window.onerror('alert(row)') to have it display the row that's giving you the error.

Lee
 
You probably changed the number of elements without thinking about it. You should really do bounds checking anyway...

Code:
    var numrows = (form.elements.length < 51)? form.elements.length : 51;

    for ( var row = 1; row <= numrows; ++row )
    {
        var kits = parseInt( frm.elements["kits"+row].value );

or just

Code:
    for ( var row = 1; row <= form.elements.length; ++row )
    {
        var kits = parseInt( frm.elements["kits"+row].value );

The other possibility is that you have one field which doesn't have a "value" parameter. In that case, you can check for that too:

Code:
var kits = (frm.elements["kits"+row].value)? parseInt( frm.elements["kits"+row].value ) : 0;

You should never assume that input exists. Always do sanity checking... not as a debug tool, but as a matter of course.

Sincerely,

Tom Anderson
Order amid Chaos, Inc.
 
The full source is below

I only see kits1 and kits2.

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
 
hey everyone...Sorry I didn't get to this thread earlier, troll helped me resolve it a while back but I didn't post that, my apologies. I went ahead and did this as he suggested

Code:
var kits = parseInt( frm.elements["kits"+row].value );

I was missing one of the rows, though I have no idea when/how that happened.

Use your resources, you're on the internet!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top