Solved

Using getElementById to update parent page without reloading

Posted on 2004-09-22
3
4,619 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

16 Experts available now in Live!

Get 1:1 Help Now