window.opener function


I am using the following code to pass data from a prent window to a child window(I am using aspx). For that I am using the code in my aspx page. In my aspx page of parent, I am having two fileds TxtRegNo as text box, and T1 as list box. To my textbox, I am getting the exact value, but to my list box, it's showing error, can any one help me, to pass value to my listbox in aspx page.



            <SCRIPT language="JavaScript">

function pick(RegNo,SName,LClass) {
  if (window.opener && !window.opener.closed)
    window.opener.document.Form1.TxtRegNo.value = RegNo;
   window.opener.document.Form1.T1.value = LClass;

// -->

Actually my LClass is the value I am getting after reading the database. for example...

I have three classes in my table ClassDetails

ClassID    ClassName

203            1-A
208            3-B
509            3-A

In LClass, I am getting 208 for example. So

window.opener.document.Form1.T1.value = 208. Now my parent window, I have a list box having all these three values, my aim is to disply 3-B as seleted in the parent window, with the other values also in list box.

If some one can help me, I am so thankful.

I have tried window.opener.document.Form1.LYear.options[LYear].selected, but in some cases it's not working

Thank you once again,
Who is Participating?
Michel PlungjanConnect With a Mentor IT ExpertCommented:
Here is a faster version (points to BI)

Also you are missing a bracket which may explain the error you sometimes got

function pick(RegNo,SName,LClass) {
  if (window.opener && !window.opener.closed) {
    window.opener.document.Form1.TxtRegNo.value = RegNo;
    var sel = window.opener.document.Form1.T1 // or LYear whatever it is called
    for (var i=0, n=sel.options.length;i<n;i++) { // only look once
       if (sel.options[i].value == LClass) {
        alert(LClass + ' found');
basicinstinctConnect With a Mentor Commented:

I think you should try this:

window.opener.document.Form1.LYear.options.selectedIndex = 1;

That will select the second item in the list (in this case 3-B).  That's assuming you know the index, otherwise you could search the list:

      for(var i=0; i < window.opener.document.Form1.LYear.options.length; i++)
            if(window.opener.document.Form1.LYear.options[i].value == '3-B')
                  window.opener.document.Form1.LYear.options.selectedIndex = i;

Of course, instead of using the literal '3-B' you could use a variable.

Hope this helps.
ceemaAuthor Commented:
Hello basicinstinct,mplungjan,

   Thank you for the reply. Both are working fine, but second one is little bit faster I think. Thank you so much for the help. I am spliting the points.

Thank you so once again  for the solution.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.