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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array value

Status
Not open for further replies.

amethystct

Programmer
Jan 26, 2004
21
FR
I have a js function for a checkbox. It's on every row of my part detail so I could have 1 - ? rows If I have more than 1 rows then the checkbox works correctly. When a user checks it I open a new page. If, however, I only have 1 row then I get an error that the value doesn't exist. Why does this happen?

This is the function. If I have only one row and I set the first field (aoms) to document.varViewPost.aoms.value then it's fine. I can't do this set if there are more than 1 rows returned though. I should still have an array of results even if it's only 1 row returned right??

function showInfo (infoObj){

var rowIndex = infoObj.name;
var formObj = document.varViewPost;
var custpo = formObj.custpo[rowIndex].value;
custpo = custpo.replace(/\W+$/,'');
var aoms = formObj.aoms[rowIndex].value;
aoms = aoms.replace(/\W+$/,'');
var partnum = formObj.partnum[rowIndex].value;
partnum = partnum.replace(/\W+$/,'');
var custCode = document.varViewPost.custcode.value;
custCode = custCode.replace(/\W+$/,'');
var contract = document.varViewPost.contract.value;
contract = contract.replace(/\W+$/,'');
var ordernum = document.varViewPost.ordernum.value;
ordernum = ordernum.replace(/\W+$/,'');

var windowwidth = 800, topheight = 600, bottomheight = 10; // default sizes
if (window.screen) {
windowwidth = window.screen.availWidth-10;
topheight = (window.screen.availHeight * 60 / 100) - 10;
bottomheight = (window.screen.availHeight * 40 / 100) - 20;
}
var UHJ = 'contractInfo.jhtml?orderNum=' + ordernum + '&custCode=' + custCode + '&AOMS=' + aoms + '&CUSTPO=' + custpo + '&PRODCODE=' + partnum;
infoObj.checked = false;
window.open(UHJ,'test','scrollbars=yes');
}


function call:
<INPUT TYPE="HIDDEN" NAME="indexVal" VALUE="0">
<INPUT TYPE="HIDDEN" NAME="rowCount" VALUE="1">
<INPUT TYPE="HIDDEN" NAME="aoms" value="3849004">
<INPUT TYPE="HIDDEN" NAME="custpo" value="3034-0125-7800">
<INPUT TYPE="HIDDEN" NAME="partnum" value="TE-6311P-1">
<INPUT TYPE="HIDDEN" NAME="login" value="taylork">
<INPUT TYPE="HIDDEN" NAME="email" value="ktaylor@usco.com">
<TD>1</TD>
<TD>3849004</TD>
<TD>3034-0125-7800</TD>
<TD>TE-6311P-1</TD>
<TD>TEMP SENSOR; 1000 OHM, NI</TD>

<TD ALIGN="CENTER">50</TD>
<TD ALIGN="CENTER">50</TD>
<TD ALIGN="CENTER">

<INPUT TYPE="checkbox" NAME="0" VALUE="moreInfo" onClick="showInfo(this);">
</TD>
 
when there is only one element of a specific name in a form, it will not be accessible by array notation. check for existence of the "length" property first:

function showInfo (infoObj){
var rowIndex = infoObj.name;
var formObj = document.varViewPost;

if (!formObj.custpo.length) {
var custpo = formObj.custpo.value;
var aoms = formObj.aoms.value;
var partnum = formObj.partnum.value;
}
else {
var custpo = formObj.custpo[rowIndex].value;
var aoms = formObj.aoms[rowIndex].value;
var partnum = formObj.partnum[rowIndex].value;
}

custpo = custpo.replace(/\W+$/,'');
aoms = aoms.replace(/\W+$/,'');
partnum = partnum.replace(/\W+$/,'');
var custCode = document.varViewPost.custcode.value;
custCode = custCode.replace(/\W+$/,'');
var contract = document.varViewPost.contract.value;
contract = contract.replace(/\W+$/,'');
var ordernum = document.varViewPost.ordernum.value;
ordernum = ordernum.replace(/\W+$/,'');

var windowwidth = 800, topheight = 600, bottomheight = 10; // default sizes
if (window.screen) {
windowwidth = window.screen.availWidth-10;
topheight = (window.screen.availHeight * 60 / 100) - 10;
bottomheight = (window.screen.availHeight * 40 / 100) - 20;
}
var UHJ = 'contractInfo.jhtml?orderNum=' + ordernum + '&custCode='
+ custCode + '&AOMS=' + aoms + '&CUSTPO=' + custpo + '&PRODCODE=' + partnum;
infoObj.checked = false;
window.open(UHJ,'test','scrollbars=yes');
}

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top