• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1466
  • Last Modified:

asp.net jquery Retrieve Parent Data from IFrame

I have an aspx (parent) page that contains various data fields and an iframe (html) page which contains hidden paypal specific fields.  upon submitting the iframe I am trying to capture the text values entered by user in the parent data field.  The code shown below is returning empty values from the parent fields. The syntax seems to be correct I am unsure what needs to be changed.

Please advise.
IFRAME Script;
    <script type="text/javascript" >
    <!--
        $(document).submit(function () {
            var donationRbl = "";
            var stateDDL = "";
            //First get the contents of the Radio button List and set to the Varible.
            var radioObj = $("[id^=<%=donation.ClientID %>]:input", window.parent.document);
            var radioLength = radioObj.length;
            for (var i = 0; i < radioLength; i++) {
                if (radioObj[i].checked) {
                    donationRbl = radioObj[i].value;
                }
            };

            $('#amount').val(donationRbl); //Set Amount field to donation selection
            $('#fist_name').val($("[id^=<%=Firstname.ClientID %>]:input", window.parent.document).val());
            $('#last_name').val($("[id^=<%=Lastname.ClientID %>]:input", window.parent.document).val());
            $('#address_street').val($("[id^=<%=Address.ClientID %>]:input", window.parent.document).val());
            $('#address_city').val($("[id^=<%=City.ClientID %>]:input", window.parent.document).val());
            $('#address_state').val($("[id^=<%=StateDDL.ClientID %>]:input", window.parent.document).val());
            $('#address_zip').val($("[id^=<%=Zip.ClientID %>]:input", window.parent.document).val());
            //$('#payer_email').val($("[id^=<%=Email.ClientID %>]:input", window.parent.document).val());

        });
    //-->
    </script>

IFRAME PayPal Fields:
                        <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
                        <input type="hidden" name="cmd" value="_donations">
                            <input type="hidden" id="hosted_button_id" name="hosted_button_id" value="MYMERCHANTID">
                            <input type="hidden" id="business" name="business" value="info@MYDOMAIN.org">
                            <input type="hidden" id="lc" name="lc" value="US">
                            <input type="hidden" id="item_name" name="item_name" value="Transitions Online Donation">
                            <input type="hidden" id="amount" name="amount" value="">
                            <input type="hidden" id="return" name="return" value="http://mydomain.org">
                            <input type="hidden" id="cancel_return" name="cancel_return" value="http://mydomain.org/ContentPages/Donations.aspx">
                            <input type="hidden" id="first_name" name="first_name" value="">
                            <input type="hidden" id="last_name" name="last_name" value="">
                            <input type="hidden" id="address_street" name="address_street" value="">
                            <input type="hidden" id="address_city" name="address_city" value="">
                            <input type="hidden" id="address_state" name="address_state" value="">
                            <input type="hidden" id="address_zip" name="address_zip" value="">
                            <input type="hidden"  id="address_country"name="address_country" value="US">
                        <input type="hidden" id="currency_code" name="currency_code" value="USD">
                        <input type="hidden" id="bn" name="bn" value="PP-DonationsBF:btn_donateCC_LG.gif:NonHosted">
                        <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
                        <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
                        </form>

PARENT ASPX:
 <div class="donationPage">
            <hr />

                    <asp:Label runat="server" ID="Title" Text="Donation Amount" AssociatedControlID="donation"/>
                        <asp:RadioButtonList runat="server" ID="donation" RepeatColumns="4" RepeatDirection="Vertical" TextAlign="right" CellPadding="10" TabIndex="1" >
                        <asp:ListItem>$5</asp:ListItem>
                        <asp:ListItem>$25</asp:ListItem>
                        <asp:ListItem>$50</asp:ListItem>
                        <asp:ListItem>$75</asp:ListItem>
                        <asp:ListItem>$100</asp:ListItem>
                        <asp:ListItem>$150</asp:ListItem>
                        <asp:ListItem>$200</asp:ListItem>
                        <asp:ListItem>$500</asp:ListItem>
                        <asp:ListItem>$1,000</asp:ListItem>
                        <asp:ListItem>$2,000</asp:ListItem>
                        <asp:ListItem>Other Amount</asp:ListItem>
                        </asp:RadioButtonList>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                        ControlToValidate="donation" CssClass="failureNotification" Display="Dynamic" 
                        ErrorMessage="Before you Submit page you must make a donation selection." ToolTip="Donation Selection." 
                        ValidationGroup="DonationValidation">*</asp:RequiredFieldValidator>
                </div><br />
                <div class="donationPage">
                    <asp:Label runat="server" ID="NameLbl" Font-Bold="true" Text="Name" />
                        <p>
                            <asp:Label ID="FirstNameLbl" runat="server" AssociatedControlID="FirstName" Text="* First name: "></asp:Label>
                            <asp:TextBox ID="Firstname" runat="server" TabIndex="2" CssClass="width17"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="FirstNameRequired" runat="server" 
                                ControlToValidate="FirstName" CssClass="failureNotification" Display="Dynamic" 
                                ErrorMessage="First Name is required." ToolTip="User's First name is required." 
                                ValidationGroup="DonationValidation">*</asp:RequiredFieldValidator>
                        </p>
                        <p>
                            <asp:Label ID="LastNameLbl" runat="server" AssociatedControlID="Lastname">* Last name:  </asp:Label>
                            <asp:TextBox ID="Lastname" runat="server" TabIndex="3" CssClass="width17"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="LastNameRequired" runat="server" 
                                ControlToValidate="Lastname" CssClass="failureNotification" Display="Dynamic" 
                                ErrorMessage="Last Name is required." ToolTip="User's Last name is required." 
                                ValidationGroup="DonationValidation">*</asp:RequiredFieldValidator>
                        </p>
                        <p>
                            <asp:Label ID="EmailAddressLbl" runat="server" AssociatedControlID="EmailAddress" Text="Email Address: " />
                            <asp:TextBox ID="EmailAddress" runat="server" TabIndex="4" CssClass="width12" />
                        </p> 
                       <p><asp:Label runat="server" id="title128" Font-Bold="true" Text="Billing Address"/></p>
                    <div>
                        <p>
                        <asp:Label ID="StreeAddressLbl" runat="server" AssociatedControlID="Address" Text="* Address: "></asp:Label>
                            <asp:TextBox ID="Address" runat="server" TabIndex="5" CssClass="width20" />
                            <asp:RequiredFieldValidator ID="ClientAddressRequired" runat="server" 
                            ControlToValidate="Address" CssClass="failureNotification" Display="Dynamic" 
                            ErrorMessage="Address is required." ToolTip="Address is required." 
                            ValidationGroup="DonationValidation">*</asp:RequiredFieldValidator>
                        </p>
                        <p>
                        <asp:Label ID="CityLbl" runat="server" AssociatedControlID="City" Text="* City: "></asp:Label>
                            <asp:TextBox ID="City" runat="server" TabIndex="6" CssClass="width12"></asp:TextBox></p>
                        <p>
                        <asp:Label ID="StateLbl" runat="server" AssociatedControlID="StateDDL" Text="* State: "></asp:Label>
                        <asp:DropDownList ID="StateDDL" runat="server" TabIndex="7" CssClass="width7">
                            <asp:ListItem Text="-Select-" Value="0"></asp:ListItem>
                            <asp:ListItem Text="AL" Value="AL" />
                            <asp:ListItem Text="AK" Value="AK" />
                            <asp:ListItem Text="AZ" Value="AZ" />
                            <asp:ListItem Text="AR" Value="AR" />
                            <asp:ListItem Text="CA" Value="CA" />
                            <asp:ListItem Text="CO" Value="CO" />
                            <asp:ListItem Text="CT" Value="CT" />
                            <asp:ListItem Text="DE" Value="DE" />
                            <asp:ListItem Text="FL" Value="FL" />
                            <asp:ListItem Text="GA" Value="GA" />
                            <asp:ListItem Text="HI" Value="HI" />
                            <asp:ListItem Text="ID" Value="ID" />
                            <asp:ListItem Text="IL" Value="IL" />
                            <asp:ListItem Text="IN" Value="IN" />
                            <asp:ListItem Text="IA" Value="IA" />
                            <asp:ListItem Text="KS" Value="KS" />
                            <asp:ListItem Text="KY" Value="KY" />
                            <asp:ListItem Text="LA" Value="LA" />
                            <asp:ListItem Text="ME" Value="ME" />
                            <asp:ListItem Text="MD" Value="MD" />
                            <asp:ListItem Text="MA" Value="MA" />
                            <asp:ListItem Text="MI" Value="MI" />
                            <asp:ListItem Text="MN" Value="MN" />
                            <asp:ListItem Text="MS" Value="MS" />
                            <asp:ListItem Text="MO" Value="MO" />
                            <asp:ListItem Text="MT" Value="MT" />
                            <asp:ListItem Text="NE" Value="NE" />
                            <asp:ListItem Text="NV" Value="NV" />
                            <asp:ListItem Text="NH" Value="NH" />
                            <asp:ListItem Text="NJ" Value="NJ" />
                            <asp:ListItem Text="NM" Value="NM" />
                            <asp:ListItem Text="NY" Value="NY" />
                            <asp:ListItem Text="NC" Value="NC" />
                            <asp:ListItem Text="ND" Value="ND" />
                            <asp:ListItem Text="OH" Value="OH" />
                            <asp:ListItem Text="OK" Value="OK" />
                            <asp:ListItem Text="OR" Value="OR" />
                            <asp:ListItem Text="PA" Value="PA" />
                            <asp:ListItem Text="RI" Value="RI" />
                            <asp:ListItem Text="SC" Value="SC" />
                            <asp:ListItem Text="SD" Value="SD" />
                            <asp:ListItem Text="TN" Value="TN" />
                            <asp:ListItem Text="TX" Value="TX" />
                            <asp:ListItem Text="UT" Value="UT" />
                            <asp:ListItem Text="VT" Value="VT" />
                            <asp:ListItem Text="VA" Value="VA" />
                            <asp:ListItem Text="WA" Value="WA" />
                            <asp:ListItem Text="WV" Value="WV" />
                            <asp:ListItem Text="WI" Value="WI" />
                            <asp:ListItem Text="WY" Value="WY" />
                        </asp:DropDownList>
                            <asp:RequiredFieldValidator ID="StateRequired" runat="server" 
                            ControlToValidate="StateDDL" CssClass="failureNotification" 
                            Display="Dynamic" ErrorMessage="Selection of State to complete address is required." 
                            InitialValue="0" ToolTip="User's Selects a State." 
                            ValidationGroup="DonationValidation">*</asp:RequiredFieldValidator>
                        </p>
                        <p>
                        <asp:Label ID="ZipLbl" runat="server" AssociatedControlID="Zip" Text="* Zip: " />
                            <asp:TextBox ID="Zip" runat="server" TabIndex="8" CssClass="width7" />
                            <asp:RequiredFieldValidator ID="ZipRequired" runat="server" 
                            ControlToValidate="Zip" CssClass="failureNotification" Display="Dynamic" 
                            ErrorMessage="Zip is required." ToolTip="Zip is required." 
                            ValidationGroup="DonationValidation">*</asp:RequiredFieldValidator>
                        </p>
                </div>
                <div>
                    <p>Upon clicking submit, you will be forwarded to PayPal to complete your donation.<br />p>

                </div><br />
                <div>
                <!--Put PayPal Button Here-->
                    <iframe id="paypalIframe" name="paypalIframe" src="../Scripts/paypalbutton.htm" style="width:100%;"  frameborder="0" scrolling="no"></iframe>
                </div><br />

Open in new window

0
Robert Treadwell
Asked:
Robert Treadwell
1 Solution
 
Miguel OzSoftware EngineerCommented:
Try replacing window.parent.document with parent.document.
if it does not work after checking that
$("[id^=<%=Firstname.ClientID %>]:input", parent.document)
does not return a valid object.

I will suggest using methods in your parent window, for example for first name your JS iframe code is :
$('#fist_name').val($("[id^=<%=Firstname.ClientID %>]:input", window.parent.document).val());

Open in new window

My suggestion wil be implemented as:
$('#fist_name').val(parent.GetFirstName());

Open in new window

where GetFirstName is defined in the parent aspx as follows:
function GetFirstName()
{
  return $("[id^=<%=Firstname.ClientID %>]:input").val();
}

Open in new window

0
 
Robert TreadwellAuthor Commented:
This solution worked exactly as suggested.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now