Link to home
Start Free TrialLog in
Avatar of ksivananth
ksivananthFlag for United States of America

asked on

The Server threw an exception

Hi Guys,

    I have a parent and child window. From the child window trying to add a item to the SELECT OPTION placed in the parent window, its giving the err "The Server threw an exception". Any idea would be appreciated.

here is the code,

window.opener.ReEntry.skills.options[ window.opener.ReEntry.skills.length + 1 ]=new Option(data.value);

window.opener.ReEntry.skills - parent widow's select option.
data.value - text input value in the child window

Best Regards,
Siva
Avatar of NetGroove
NetGroove

Hello Siva,

this is a standard problem that you try to fetch memory in a popup window for object referenced in parent window.
The new Option() reserves memory for the options.

Second problem is that your form is child of document, not of window.

Better is to do it like this:

  popform = document.forms[0];
  opt = window.opener.document.ReEntry.skills.options;
  newOpt = opt.length;
  opt[newOpt].text =  popforn.data.value;
  opt[newOpt].value =  popforn.data.value;


Good luck,
NetGroove


ASKER CERTIFIED SOLUTION
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
So, on the parent window, create a function called addItem()

function addItem(strValue,strText){
   var objSel = document.forms['ReEntry'].elements['.skills'];
   objSel[objSel.length].value =  strValue;
   objSel[objSel.length].text =  strText;
}


and then you can call it from you child like this:

window.opener.addItem('Excel','Microsoft Excel');

Sorry, my version contained several typos.

Here a tested version:

<html>
<head>
<script>
function addOpt(){
 popform = document.forms[0];
 opt = window.opener.document.ReEntry.skills.options;
 newOpt = opt.length;
 opt.length = newOpt+1;
 opt[newOpt].text = popform.data.value;
 opt[newOpt].value = popform.data.value;
}
</script>
</head>
<body>
<form>
<input type=text name="data">
<input type=button value=Add onClick="addOpt()">
</form>
</body>
</html>


And the parent form is something like this:
<html>
<body>
<form name=ReEntry>
<select name=skills>
<option>One
</select>
<input type=button value=Add onClick="open('popsel.htm','pop','height=200,width=300')">
</form>
</body>
</html>


Hello Siva,

is your problem now solved?
Do you need more help?

Avatar of ksivananth

ASKER

Hi Guys,

    Thank ypu so much for your helps.

I solved the issues using the Comment from fritz_the_blank on
Date: 11/24/2003 05:50AM PST.

    Sorry NetGroove, I tried the way u suggested before posting this question but it doesn't work. Yo are saying it works for you, probably you would have tested in Netscape, try it in IE, you'll get the same err.

    So I am giving the points to fritz_the_blank!

Thanks & Regards,
Siva

Glad to have helped,

FtB