window.opener function

Posted on 2006-05-13
Last Modified: 2012-08-14

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,
Question by:ceema
    LVL 23

    Assisted Solution


    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.
    LVL 75

    Accepted Solution

    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');

    Author Comment

    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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Adobe Dreamweaver CC 2015

    Adobe Dreamweaver Creative Cloud is used by web designers and front-end developers and allows you to visualize your site in real-time as you code. This course covers exam objectives for the Adobe Certified Associate (ACA) certification.

    Suggested Solutions

    Title # Comments Views Activity
    network + 7 57
    Pass custom headers using request module 1 21
    jquery 3 and protoype 9 23
    Search box won't work. 22 15
    Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
    In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
    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…

    758 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

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now