Solved

Using getElementById to update parent page without reloading

Posted on 2004-09-22
3
4,625 Views
Last Modified: 2008-02-01
Hi!

I have 2 pages Main.aspx and detail.aspx. The first page is a DIV The second page(detail.aspx) is an IFRAME.
When I click the edit button on the main page, it opens up the Iframe on the bottom.
When I update the individual record in the iframe on the bottom, should update the record on Main.aspx without reloading.

So I use getElementById() to get the values and assign them to the parent document.
The problem occurs when I want to use parent.document.getElementById()   or window.opener.document.getElementById()
here is a snippet.

<SCRIPT language ="javascript" id="UpdateMain">
            function UpdateMain() {
            for (i=0; i < document.all.length; i++)
            //storeid =stid ; customerid = custid  Detailid = checkbox.checked status
            var stid= document.getElementById('txtStoreID').value
            var custid= document.getElementById('TxtCustomerName').value
            var Detailid = document.getElementById('chkcontacted').checked

            var idSearch= window.parent.document.body.id
            //alert("My id is  : " + idSearch + " " )
                  
      //using DHTML document.getElementById Method to update Parent            
      window.parent.document.getElementById('DataGrid1__ctl[i]_IContacted').value=Detailid;
                  alert("The Current Status  For : " + stid + " " + custid + " is " +  Detailid  );
            //using url to update parent.
      //var url = 'Main.aspx?storeid=stid&Customerid=custid&DataGrid1__ctl[i]_IContacted.checked=Detailedid';
      //      location.href=url;
                  }

            </SCRIPT>

Your help is appreciated.
0
Comment
Question by:externet
  • 2
3 Comments
 

Author Comment

by:externet
ID: 12137179
There was a typo in the previous message:  'DataGrid1__ctl[i]_IContacted' should have been 'DataGrid1__ctl'+[i]+'_IContacted'.  

This block is now  //using DHTML document.getElementById Method to update Parent
             parent.document.getElementById('DataGrid1__ctl'+[i]+'_IContacted').value=document.getElementById('chkcontacted').checked;

when I click submit in the iframe, the parent is updated but the display in the div  does not refresh. Why?

             
0
 
LVL 15

Accepted Solution

by:
Thogek earned 500 total points
ID: 12191960
The above function looks very confused.  You have three distinct variables you are accessing ('txtStoreID', etc.), the first of which is under a for-statement (no braces means only the first line under the for is looped).  You then later set one of these values to an indexed control in the parent page 'DataGrid1__ctl[i]_IContacted'....  Looks very muddled.

Can you check that this is indeed the exact code that you are running (i.e., that appears in the "View Source" HTML of the page), and post exactly what *is* happening when you run it?
 
0
 

Author Comment

by:externet
ID: 12199502
Hello Thogek,
Thanks for your suggestions. I  have had a solution which is as follows:
function UpdateMaster() {
            <!--
            var stid= document.getElementById('txtStoreID').value
            var custid = document.getElementById('txtCustomerID').value
            var chkValue = document.getElementById('chkcontacted').checked
            var currentId = stid + "_" + custid
            parent.document.getElementById(currentId).children[0].checked=chkValue;
            
             }
      -->
      </script>
I had two Issues: The Datagrid control associates itself to the elementid.  So I Inserted a checkbox control within a <span> to maintain my id (stid + "_" + custid) unique and free from the datagrid control.  Every works now as expected.
The second issue as you indicated was my for- statement which you indicated from your reply.  
Again Thanks.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

785 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