Click to See Complete Forum and Search --> : Getting the index from a checkbox array


Evie
10-31-2003, 07:54 AM
I hope this isn't already here somewhere!

I am needing to find out what the index is of a checkbox so if there is a certain permission flipped, it unchecks it.

(Actually, if you can tell me how to uncheck it, that would be fab!)

Here's the object:
<input type="checkbox" name="chkAddToOrder" value="6546" alt="Microtec_Assmblr(80386+CPU)x86_PC_WINNT_NL" onclick="if(this.checked){JPMMProd(this.alt, this.index);}">

All the checkboxes on the form are 'chkAddToOrder' (I need them to be an array)

Here is the script:

function JPMMProd(engname, chkindex){
var orderid=document.NucList.orderid.value;
alert('Be sure to get PMM Approval for this product befor submitting to your Sales Manager');
document.NucList.chkAddToOrder[chkindex].click();
url="EmailFromSelectNucProds?orderid="+orderid+"&engname="+engname;
alert(url);
//window.hiddenWindow.location.href=url;
}

TIA

-Evie

Khalid Ali
10-31-2003, 08:11 AM
This may be a pretty good resource for you to learn more about controlling most of the aspects of checkboxes

http://www.webapplikations.com/pages/html_js/forms/CheckBoxesLimitUserSelection.html

Evie
11-03-2003, 11:54 AM
Thanks for the link! I was able to at least figure out how to uncheck the box.

However, that code didn't suit my needs. It goes in a loop and 'redoes' everything.

I have a page with a dynamic number of checkboxes. When one is checked and it has a certain value, I want to pop a box up giving them information and run an SSL email script, and maybe even uncheck the box, depending on the permissions of the user.

I don't need the message to pop up every time it comes across a checked box and I certainly do not need to resend the email x number of times.

I just want to know how to get the index value passed. If that is impossible, I'll try to figure out some other way to determine which box has been checked.

TIA!

Evie
11-04-2003, 11:09 AM
I figured out a solution. I am already passing alt text so I can push that information to the page I am emailing from, so I just compare the alt text of the current form obj to the text I passed in and viola! :D

function JPMMProd(engname, obj){
var frm=document.getElementById("frmNucMResults");
for(i=0;i<frm.length;i++){
if(frm[i].checked && frm[i].type=="checkbox" && frm[i].alt==engname){
alert('Be sure to get PMM Approval for this product before submitting to your Sales Manager');
var orderid=document.NucList.orderid.value;
url="EmailFromSelectNucProds?orderid="+orderid+"&engname="+engname;
alert(url);
//window.hiddenWindow.location.href=url;
<:unless "deptid==29 or deptid==8">
frm[i].checked = false;
</:unless>
}
}
}