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!

checkbox issue

Status
Not open for further replies.

amethystct

Programmer
Jan 26, 2004
21
FR
Hi!

I have a function that WAS working beautifully. I have a page that displays some query rows for me. I had a form for each row but it had to be changed when other form input was added. Now instead of the form being on each row it's just one form. I hope this makes sense!

What's happening is the document.forms[index] is now null. Can I get the whole array of values for the checkbox and see which one the user checked instead?

Here's the function:
function showInfo (infoObj){
alert("In showinfo:" + infoObj);
if (infoObj.checked) {
alert("In showInfo. Box is checked");
var rowIndex = infoObj.name;
alert("Row index: " + rowIndex);
alert("test2: " + document.forms[rowIndex]);
var custCode = document.forms[rowIndex].custcode.value;
custCode = custCode.replace(/\W+$/,'');
alert("cust: " + custCode);
var aoms = document.forms[rowIndex].aoms.value;
aoms = aoms.replace(/\W+$/,'');
alert("aoms: " + aoms);
var contract = document.forms[rowIndex].contract.value;
contract = contract.replace(/\W+$/,'');
alert("contract: " + contract);
var custpo = document.forms[rowIndex].custpo.value;
custpo = custpo.replace(/\W+$/,'');
alert("Po: " + custpo);
var partnum = document.forms[rowIndex].partnum.value;
partnum = partnum.replace(/\W+$/,'');
alert("part: " + partnum);
var ordernum = document.forms[rowIndex].ordernum.value;
ordernum = ordernum.replace(/\W+$/,'');
alert("ordernum: " + ordernum);
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;
}
alert("set window");
var UHJ = 'contractInfo.jhtml?orderNum=' + ordernum + '&custCode=' + custCode + '&AOMS=' + aoms + '&CUSTPO=' + custpo;
infoObj.checked = false;
alert("set page info and reset box to false");
window.open(UHJ,'test','scrollbars=yes');
}
}

called:
<INPUT TYPE=&quot;checkbox&quot; NAME=&quot;param:index&quot; VALUE=&quot;moreInfo&quot; onClick=&quot;showInfo(this);&quot;>
 
Looks to me like you are trying to look at more than one form when you use forms[row]. You now only have one form so you need to point to the arrays inside the form instead.
When I have done similar before I have created my row with an id like...

<input id=&quot;row&quot;+ rownum type=&quot;checkbox&quot; etc>

so i can iterate through each input using document.getElementById(&quot;row&quot;+index).value...
or
document.formid.input[index] (not done this before but I think it works like this)

Hope this helps. I can dig some code out if you're not sure about the above so let me know.
 
The code originally was for multiple forms. Moving the form outside my loop is what broke this. I'm trying to change it to give me the value of the form elements for the row that was checked. I don't need the check box value, that's just set to the row index. I need the value of some other elements on that row. That's the problem I'm having. Using getElementById I get the name of my checkbox. I need custcode, aoms, etc... from the row that was checked.
 
Fixed it. I feel like a dummy now!!

var formObj = document.varViewPost;

var custCode = document.varViewPost.custcode.value;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top