Solved

Using getElementById to update parent page without reloading

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convert to Hour/minute textbox and compare 3 52
What .NET website keeps me current? 9 52
ADO.NET ENTITY DATA MODEL 3 30
SQL Exceptions 3 35
Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

930 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

15 Experts available now in Live!

Get 1:1 Help Now