Forum Moderators: open

Message Too Old, No Replies

Help with javascript popup

that sends info to parent form

         

mjar81

8:22 pm on Jun 8, 2005 (gmt 0)

10+ Year Member



OK, this might be a long one, but my script works in Firefox and not in IE. Maybe someone can tell me why.

I have a main page with a form that has a multiple select list box called "catid" (category ID) and the form is named "inform".

i use a button to open a popup window and have a list of categories that the user can select. When one is clicked, it adds the selection to the list in the main page and selects it while keeping the category popup in front so that they can select another category.

here's the code from my popup window:


<SCRIPT LANGUAGE="JavaScript">
<!--//

function addCat(x, y) {
opnum = self.opener.document.inform.catid.length;
var exists = false;
var k = 1;
for (k = 0; opnum - 1 >= k ; k++) {
if (self.opener.document.inform.catid.options[k].value == y) {
exists = true;
}
}
if (!exists) {
cat = new Option(x, y, true, true);
self.opener.document.inform.catid.options[opnum] = cat;
self.opener.document.inform.catid.options[opnum].selected = true;
self.opener.document.inform.catid.options[0].selected=false;
alert( x + " has been added to list.");
} else {
alert( x + " already in list.");
}
return true;
}

//-->
</SCRIPT>
<A HREF="#" ONCLICK="return addCat('PC Components & Peripherals', 1)">PC Components & Peripherals</a><br>
<A HREF="#" ONCLICK="return addCat('Components', 10)">Components</a><br>
<A HREF="#" ONCLICK="return addCat('Batteries', 100)">Batteries</a><br>
<A HREF="#" ONCLICK="return addCat('Chargers', 8340)">Chargers</a><br>
<A HREF="#" ONCLICK="return addCat('Display Stand', 8341)">Display Stand</a><br>
<A HREF="#" ONCLICK="return addCat('Lithium Ion', 8338)">Lithium Ion</a><br>
etc...

can anyone tell me why explorer gives a javascript error? (Line 15, Char 5, Error: Server threw exception, Code: 0)

kikecomp

9:31 pm on Jun 29, 2005 (gmt 0)



Hi,
I was having the same problem... one way to solve is this... here in brazil we name this kind of solution as "GAMBI"...

<SCRIPT LANGUAGE="JavaScript">
<!--//

function addCat(x, y) {
opnum = self.opener.document.inform.catid.length;
var exists = false;
var k = 1;
for (k = 0; opnum - 1 >= k ; k++) {
if (self.opener.document.inform.catid.options[k].value == y) {
exists = true;
}
}

if (!exists) {
cat = self.opener.document.createElement("option");
catid = self.opener.document.inform.catid;
textDysplayed = self.opener.document.createTextNode(x);
cat.setAttribute("value",y);
cat.appendChild(textDysplayed);
catid.appendChild(cat);
alert( x + " has been added to list.");
} else {
alert( x + " already in list.");
}
return true;
}

//-->
</SCRIPT>
<A HREF="#" ONCLICK="return addCat('PC Components & Peripherals', 1)">PC Components & Peripherals</a><br>
<A HREF="#" ONCLICK="return addCat('Components', 10)">Components</a><br>
<A HREF="#" ONCLICK="return addCat('Batteries', 100)">Batteries</a><br>
<A HREF="#" ONCLICK="return addCat('Chargers', 8340)">Chargers</a><br>
<A HREF="#" ONCLICK="return addCat('Display Stand', 8341)">Display Stand</a><br>
<A HREF="#" ONCLICK="return addCat('Lithium Ion', 8338)">Lithium Ion</a><br>