...

View Full Version : Adding & removing values from hidden field



angst
01-08-2007, 06:47 PM
Hello,
I've got several checkbox on a page, I need to be able to added and remove the values of the check box to and from a hidden text field in another form on the same page, but I'm having some issues with the indexOf function.

my code so far:


function AddOrderID(numOrderID){

var strHidden = document.RegForm.ItemIDs
if(strHidden.indexOf(numOrderID) == 0){
strHidden.value = strHidden.replace(/' + numOrderID + '/, "")
} else {
if(strHidden.value !== ""){
strHidden.value = strHidden.value + "," + numOrderID;
} else {
strHidden.value = numOrderID;
}
}
}


I'm not sure what i'm doing wrong here, i've searched good, and it *looks* like i'm using correctly, but i keep getting an error while trying to execute the script: "Object doesn't support this property or method".

any help would be great,

thanks in advance for your time!
-Ken

angst
01-08-2007, 07:00 PM
ok, I've cut down the code a bit, and found that i needed to add ".value" to my object calls. that fixed the errors,
but still i can't seem to remove the values from the hidden field, I can only added them.

my code:


function AddOrder(numOrderID){

var strHidden = document.RegForm.ItemIDs;
if(strHidden.value.indexOf(numOrderID + ',') > 0){
strHidden.value = strHidden.value.replace(/' + numOrderID + '/, "");
} else {
strHidden.value = strHidden.value + numOrderID + ',';
}
}


any ideas?

thanks again for your time!
-Ken

angst
01-08-2007, 07:15 PM
oh, i've figured it all out,



function AddOrder(numOrderID){

var strHidden = document.RegForm.ItemIDs;
if(strHidden.value.indexOf(numOrderID + ',') == 0 || strHidden.value.indexOf(numOrderID + ',') > 0){
strHidden.value = strHidden.value.replace(numOrderID + ',', "");
} else {
strHidden.value = strHidden.value + numOrderID + ',';
}
}


all the examples i used were for static data, sorry for being such a newb! ;-)

-Ken

david_kw
01-08-2007, 07:18 PM
I'm not sure exactly what you are doing, but try changing the test to:

if(strHidden.value.indexOf(numOrderID + ',') >= 0){

since indexOf returns -1 on failure, not 0.

david_kw

ha! you beat me to it. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum