CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Jun 2008
    Posts
    142

    Problem to open popup in IE

    Hi,

    I am facing problem to open a popup window in IE. But it works fine in Mozilla. I am getting an error as : 'document.forms[..].elements' is null or not an object' But i am passing value. and using the following code. 1st alert is working, 2nd alert is not able to open.

    Code:
    function openCompanyPopup( formName, idField, nameField )
      {
        customerPopupForm = formName;
        customerPopupIdField   = idField;
        customerPopupNameField = nameField;
        alert('formName'+formName);
        alert(document.forms[formName].elements[nameField].value);
        var popupURL = "ozSlsLOVCompany.jsp?searchParam="+document.forms[formName].elements[nameField].value;
        var lovWin = window.open(popupURL, 'LOVCompany', 'left=100,top=60,width=700, height=540, scrollbars=yes');
        lovWin.opener = self;
        lovWin.focus();
      }
    thanks..

  2. #2
    Join Date
    Jul 2005
    Location
    Currently in Mexico City
    Posts
    568

    Re: Problem to open popup in IE

    Instead of forms["formName"] use the formName directly or by form's index: document.myForm or document.forms[0].

    With elements it would depend on what exactly you want.

    For any type of element:
    I'd recommend using id attribute, so you could use document.getElementById("myElementID") to access a specific element. Also if you need something more generic (say make some changes to all the elements of the same type, etc.) use document.getElementsByTagName("*") or document.getElementsByTagName("DIV") to get all the elements (or of the same type) of the page and then go through the resulting array filtering them by some property you need. Just do not use document.all for this.

    For form only fields:
    To get to some specific field by its name use: document.myForm.myElementName.
    Or you could lits elements of a form by name: document.getElementsByName("elName"). If you need all of them do as above document.myForm.getElementsByTagName("*"). These would give a list of elements you would need to iterate through to get something specific of course.

    Now regarding your method:

    If you need just to pass a parameter you do not need the form, id and name at the same time. An id or a name would do it:
    PHP Code:
    function openCompanyPopup(idFieldnameField){
        var 
    param document.getElementById(idField).value;
        
    //same thing as:
        
    var param document.getElementsByName(nameField)[0].value//considering we need the first occurance
        
    ... 
    If it's imperative we use all three, then:
    PHP Code:
    function openCompanyPopupformNameidFieldnameField ){
        
    customerPopupForm document.getElementsByName(formName)[0];
        
    customerPopupIdField document.getElementById(idField);
         
    customerPopupNameField null;
         
    //2 different forms on the same page can have 2 fields with the same name.
         //Let's suppose nameField is a name of an input element, then:
         
    formInputs customerPopupForm.getElementsByTagName("INPUT");
         for(var 
    i=0i<formInputs.lengthi++){
             if(
    formInputs[i].name == nameField){
                 
    customerPopupNameField formInputs[i];
             }
         }
         
    //you do not need to know the form name here since
         //you already have an element object you can access to
        
    var popupURL "ozSlsLOVCompany.jsp?searchParam="+customerPopupNameField.value;
        var 
    lovWin window.open(popupURL'LOVCompany''left=100,top=60,width=700, height=540, scrollbars=yes');
        
    lovWin.opener self;
        
    lovWin.focus();

    (don't worry, it's JS, php tags are just for code coloring)
    Last edited by Xeel; June 2nd, 2009 at 01:03 PM.
    Wanna install linux on a vacuum cleaner. Could anyone tell me which distro sucks better?

    I had a nightmare last night. I was dreaming that I’m 64-bit and my blanket is 32-bit and I couldn’t cover myself with it, so I’ve spent the whole night freezing. And in the morning I find that my blanket just had fallen off the bed. =S (from: bash.org.ru)

    //always looking for job opportunities in AU/NZ/US/CA/Europe :P
    willCodeForFood(Arrays.asList("Java","PHP","C++","bash","Assembler","XML","XHTML","CSS","JS","PL/SQL"));

    USE [code] TAGS! Read this FAQ if you are new here. If this post was helpful, please rate it!

  3. #3
    Join Date
    Jun 2008
    Posts
    142

    Re: Problem to open popup in IE

    hey thanks for reply.
    with the following code as per your updates it is opening the popup window.
    Code:
    function openCompanyPopup( formName, idField, nameField )
      {
         customerPopupForm = document.getElementsByName(formName)[0];
        customerPopupIdField   = document.getElementById(idField).value;
        customerPopupNameField = null;
        alert(customerPopupIdField);
        
        var formInputs = customerPopupForm.getElementsByTagName("INPUT");
        for(var i=0; i<formInputs.length; i++){
             if(formInputs[i].name == nameField){
                 customerPopupNameField = formInputs[i];
             }
         }   
        var popupURL = "ozSlsLOVCompany.jsp?searchParam="+customerPopupNameField.value;
        var lovWin = window.open(popupURL, 'LOVCompany', 'left=100,top=60,width=700,height=540,scrollbars=yes');
        lovWin.opener = self;
        lovWin.focus();
      }
    Last edited by adusumalli; June 3rd, 2009 at 02:58 PM.

  4. #4
    Join Date
    Jun 2008
    Posts
    142

    Re: Problem to open popup in IE

    It is opening the pop up window with the above code. But problem is when i open a popup window if i choose one of option by radio button and selected value should update in parent window of text box, for that i used the following method. but the popup window is not closing with the selected value. so what i need to update in the following JS method.
    Code:
    function acceptLOVCompany( id, cn )
      {
        document.forms[customerPopupForm].elements[customerPopupNameField].value = URLDecode(cn);
        document.forms[customerPopupForm].elements[customerPopupIdField].value = id;
      }
    Last edited by adusumalli; June 3rd, 2009 at 02:58 PM.

  5. #5
    Join Date
    Jun 2008
    Posts
    142

    Re: Problem to open popup in IE

    when i try it as like this it is giving an error as "document.getElementById(..)" is null or not an object. i updated like this :
    Code:
    function acceptLOVCompany( id, cn )
      {
          document.getElementsByName(customerPopupNameField).value = URLDecode(cn);
          document.getElementById(customerPopupIdField).value = id;
      }

  6. #6
    Join Date
    Jun 2008
    Posts
    142

    Re: Problem to open popup in IE

    any body give an idea ??

  7. #7
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Problem to open popup in IE

    What's the value for? customerPopupNameField
    Sounds like your NULL

    Code:
    function acceptLOVCompany( id, cn )
      {
          document.getElementsByName(customerPopupNameField).value = URLDecode(cn);
          document.getElementById(customerPopupIdField).value = id;
      }
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  8. #8
    Join Date
    Jun 2008
    Posts
    142

    Re: Problem to open popup in IE

    customerPopupNameField is the 'Name' of the selected value in popup window and which is display in parent window text filed.
    Last edited by adusumalli; June 3rd, 2009 at 02:10 PM.

  9. #9
    Join Date
    Jul 2005
    Location
    Currently in Mexico City
    Posts
    568

    Re: Problem to open popup in IE

    Where the acceptLOVCompany() method is? If it's in the main page then how do you pass the customerPopupNameField parameter?

    Do not forget the objects are window dependent. If you want to execute a function from one window taking a parameter from another be sure to identify the correct window.
    - http://www.quirksmode.org/js/popup.html - js popup reference
    - http://www.codingforums.com/archive/...p/t-32389.html - thread on passing params between windows
    Wanna install linux on a vacuum cleaner. Could anyone tell me which distro sucks better?

    I had a nightmare last night. I was dreaming that I’m 64-bit and my blanket is 32-bit and I couldn’t cover myself with it, so I’ve spent the whole night freezing. And in the morning I find that my blanket just had fallen off the bed. =S (from: bash.org.ru)

    //always looking for job opportunities in AU/NZ/US/CA/Europe :P
    willCodeForFood(Arrays.asList("Java","PHP","C++","bash","Assembler","XML","XHTML","CSS","JS","PL/SQL"));

    USE [code] TAGS! Read this FAQ if you are new here. If this post was helpful, please rate it!

  10. #10
    Join Date
    Jun 2008
    Posts
    142

    Re: Problem to open popup in IE

    acceptLOVCompany() is calling from ozSlsLOVCompany.jsp which is popup window. From popup window i am calling that method. See the below code in popup window.
    Code:
       <html><head>
          <script language="JavaScript">
           function returnValue( id, cn )
           {
             opener.acceptLOVCompany(id, cn );
             self.close();
           }
        </script></head>
        <body>
          <script language="JavaScript">
            var id = '<&#37;=id%>';
            var cn = '<%=AhsStringUtil.jsEncode(cust.getDisplayName())%>';
            returnValue(id,cn);
          </script>
        </body>
        </html>
    In the parent window i wrote the following methods.
    Code:
      var customerPopupForm;
      var customerPopupNameField;
      var customerPopupIdField;
      function openCompanyPopup( formName, idField, nameField )
      {
        customerPopupForm = document.getElementsByName(formName)[0];
        customerPopupIdField   = document.getElementById(idField).value;
        customerPopupNameField = null;
        alert(customerPopupIdField);
        
        var formInputs = customerPopupForm.getElementsByTagName("INPUT");
        for(var i=0; i<formInputs.length; i++){
             if(formInputs[i].name == nameField){
                 customerPopupNameField = formInputs[i];
             }
         }   
        var popupURL = "ozSlsLOVCompany.jsp?searchParam="+customerPopupNameField.value;
        //  var popupURL = "ozSlsLOVCompany.jsp";
        var lovWin = window.open(popupURL, 'LOVCompany', 'left=100,top=60,width=700,height=540,scrollbars=yes');
        lovWin.opener = self;
        lovWin.focus();
      }
    
                  
      function acceptLOVCompany( id, cn )                // this method calling from popup
      {
         //document.forms[customerPopupForm].elements[customerPopupNameField].value = URLDecode(cn);
         //document.forms[customerPopupForm].elements[customerPopupIdField].value = id;
          document.getElementsByName(customerPopupNameField).value = URLDecode(cn);
          document.getElementById(customerPopupIdField).value = id 
      }
    thanks..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured