Jump to content

array popping and joining


nadeemshafi9

Recommended Posts

hello hers the code

function addtoparent(id){
var relations = window.opener.document.getElementById('add_item_frm').product_relations.value;
var relArray = relations.split(",");
var action = "yes";

for(a in relArray) 
{
	if(relArray[a] == id) {
		action = "no";
		newRelArray = relArray.splice(a-1,1);
	}
}

if(action != "no") {
  		window.opener.document.getElementById('add_item_frm').product_relations.value = window.opener.document.getElementById('add_item_frm').product_relations.value + "," + id;
}
else {
	window.opener.document.getElementById('add_item_frm').product_relations.value = "," + newRelArray.join();
}
}

 

the parent window opens a child window using another function, this functiuon is used to add items to a textfeild like 324324,234324,234234 its done by checking the checkbox, but if u uncheck the checkbox it disapears of the parent windows textbox what happens is i do it on the onchange() of the check item and feed it the ID. whats happening is that i can add 3 id's 3434,32434,23432 and then when i try to remopve one they all get removed, but if i add 2 and remove 1 it works and if i add 1 and remove one it works, rember it has to remove the right id from the concatinated string in the parents textbox when i unchgeck the box it should know that the string has the id in it alrerady and force remove.

 

thanks for any sugestions at all

Link to comment
https://forums.phpfreaks.com/topic/75509-array-popping-and-joining/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.