?
Solved

window.opener function

Posted on 2006-05-13
3
Medium Priority
?
1,368 Views
Last Modified: 2012-08-14
Hello,

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.

Thnaks
Ceema


Code:

<head>
            <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;
   alert(LClass);
   
 window.close();
 
}

// -->
            </SCRIPT>
      </HEAD>



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,
Ceema
0
Comment
Question by:ceema
3 Comments
 
LVL 23

Assisted Solution

by:basicinstinct
basicinstinct earned 200 total points
ID: 16673549
Hi

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;
                  break;
            }
      }

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

Hope this helps.
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 800 total points
ID: 16674531
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) {
        sel.options[i].selected=true;
        alert(LClass + ' found');
        break;
      }
    }
  }
  window.close();
}
 
0
 

Author Comment

by:ceema
ID: 16676541
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.

Regards
Ceema
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question