How do i update/add new records via an Iframe joined with the main page? **Urgent** Please Help!

Posted on 2006-04-06
Last Modified: 2013-12-24
Hello Experts,

My second question as the first was not answered, may be because it was too long.


I am trying to add new and update records in two different tables. Currently the data from the parent table is displayed on the page whereas the child tables's data is displayed using an iframe.

This makes it tricky to add a new record when both these sections are connected via a primary key:ProductCode.

I am strugling with this and need your help in implementing two different functionalities on this page.

1. Adding new records

Where the parent and child tables will both have a new record entered.

2. Updating existing records

where the record currently displayed on the form can be updated.

Ok this is the scenario i am trying yo make it work.

1. User clicks the Add New product button. Result: all the fields on form would become blank so the user can add new info. This includes the iframe. Once the user has finished entering the data, he/she would click on submit changes and then the data would be passed through to the savechanges.cfm file.

2. User clicks on update product details button. Result a new row is added within the iframe data so that the user can add new data for the particular product being displayed on screen. Once the user has finished entering the new data, he/she would then click on submit changes and then the data would be passed through to a savechanges.cfm file.

I am not sure how to go about this. I have managed to display the data but i really need to ass this functionality of adding and editing data.

All help and ideas on how to achieve this will be highly appreciated.


Question by:Navgod
    LVL 10

    Expert Comment

    on the main page, when you open the iframe, pass the current product id to the iFrame's page.


    <cfoutput query="getProd">
       product: #getProd.productName#

        <iframe name="prodDetails.cfm?">

    Then your 'child' page knows what product you are working on.

    This is a general idea how this.
    LVL 9

    Accepted Solution

    Since you are already going to be getting a page refresh with a form submission why not just eliminate the iframe for the child information on the add/update.  That way you'll have less problems with validation etc... say the page has three states which are passed by a URL parameter (1=view, 2=add, 3=edit).
    Example page:

    <cfif IsDefined("FORM.submit")>
       <cfif IsDefined("FORM.recordID") AND IsNumeric(FORM.recordID)>
           ... Place processing code & query(s) for updating the edited record of the passed recordID value ...
           ... Place processing code & query(s) inserting a new record based on passed values ...
    <cfparam name="url.view" default="1">
    <cfswitch expression="#url.view#">
    <cfcase value="1">
    ... Your current display page code here ...
    <cfcase value="2">
    ... Single form with all of the information required for an insert ...
    <cfcase value="3">
    ... Copy of the add form except with a hidden recordID field and values for each of the corresponding inputs ...

    Since the form processing occurs before each page version's display area, updates will be reflected in the view page.  Both forms in this case would have an action="myPageName.cfm?view=1" so that after a form submission they would return to the display version of the page.

    Not sure if that's what you want, but it would work for you.  It's difficult to write an example based on your description (or more specifically the issues that might come up in handling a dual-page submission - iframe).  That solution would need some javascript behind it I think, but I could be wrong about that.  I haven't used iframes in this way on a form, but from what I know, I think they are dealt with in the browser as a totally separate page layer.

    Author Comment


    The reason i am having the iframe is because i am upsizing a previous access database, and am under strict instructions to make the new design look similar to the forms designed in access.

    This is the code i have so far.


      <cfparam name="url.a" default="menu">
      <cfparam name="" default="">
      <cfparam name="startrow" default="1">
        <form name="search" action="index.cfm?a=horsham_exports&search=yes" method="post">
        <table width="720" cellpadding="0" cellspacing="0" align="center"><tr><td align="center"><h3>Horsham Exports</h2></td></tr></table>
        <cfquery name="get_products" datasource="dt446">
          select * from tblhorsham_exports order by description asc

        <cfif is "yes">
          <cfoutput query="get_products">
            <cfparam name="count" default="1">
            <cfif form.productcode eq #productcode#>
              <cfset startrow = #count#>
              <cfset count = count + 1>
            <cfset PRODUCTCODE = #FORM.PRODUCTCODE#>

        <!--- Set the default startrow to 1 if a value was not passed. --->
        <!--- Determine whether or not to show the previous or next links. --->
        <cfparam name = "StartRow" default = "1">
        <!--- Set the value of endrow to the maxrows + startrow - 1 --->
        <cfset EndRow = StartRow + 1 - 1>
        <!--- If the end row is greater than the recordcount, determine how many records are left. --->

        <cfif EndRow GTE get_products.RecordCount>
          <cfset EndRow = get_products.RecordCount>
          <cfset Next = false>
          <!--- Otherwise, set Next to true and determine the next set of records. --->
          <cfset Next = true>
          <cfif EndRow + 1 GT get_products.RecordCount>
            <cfset NextNum = get_products.RecordCount - EndRow>
            <cfset NextNum =  1>
         <cfset NextStart = EndRow + 1>
        <!--- If StartRow is 1, set Previous to false. --->
        <cfif StartRow IS 1>
          <cfset Previous = false>
        <!--- Othewise, determine the previous set of records. --->
          <cfset Previous = true>
          <cfset PreviousStart = StartRow - 1>
        <!--- Determine how many pages will be displayed. --->
        <cfset NumPages = Ceiling(get_products.RecordCount / 1)>
        <cfparam name = "PageNum" default = "1">

        <cfoutput query="get_products" maxrows="1" startrow="#STARTROW#">

        <cfquery  name="get_shipping" datasource="dt446">
          select * from tblhorsham_exports_pack_details where productcode = '#productcode#'

        <table width="720" cellspacing="1" cellpadding="4" bgcolor="cccccc" align="center">
          <tr bgcolor="19569B">
            <td colspan="8" bgcolor="19569B" class="large_white">PRODUCT DETAILS</td>
          <tr bgcolor="ffffff">
            <td width="100">Product Code:</td>
            <td width="100">#productcode#</td>
            <td width="70">Type:</td>
            <td width="70">#type#</td>
            <td width="90">Source:</td>
            <td width="50">#source#</td>
            <td colspan="2" rowspan="3" align="center"><img src="images/packaging.jpg" border="0"></td>
          <tr bgcolor="ffffff">
            <td>Packaging Line:</td>
            <td>Pack Size:</td>
          <tr bgcolor="ffffff">
            <td colspan="5">#description#</td>
          <cfset session.startrow = #startrow#>
          <cfset session.productcode = #productcode#>

        <table width="720" cellspacing="1" cellpadding="3" bgcolor="cccccc" align="center">
            <tr bgcolor="19569B">
              <td class="large_white">PACKAGING INFORMATION -  <font color="red">Weight (grms/Pack)</font></td>
              <td><iframe align="left" marginheight="3" marginwidth="3" height="100" width="100%" frameborder="0" scrolling="yes" name="packaging" src="iframe.cfm"></iframe></td>
        <TABLE width="720" BORDER = "0" cellspacing="1" cellpadding="3" bgcolor="cccccc" align="center">
          <TR bgcolor="#19569B" style="color:#FFFFFF;font-weight:bold">
            <TD width="141" align="center">
              <!--- If Next is true, display the previous link. --->
              <CFOUTPUT><A HREF = "index.cfm?StartRow=1&a=horsham_exports" style="color:##FFFFFF">&lt;&lt; First Record &nbsp;</A></CFOUTPUT></TD>
            <TD width="140" style="color:##FFFFFF" align="center">
              <!--- If Previous is true, display the previous link. --->
              <cfif Previous>
                <CFOUTPUT><A HREF = "index.cfm?StartRow=#PreviousStart#&PageNum=#DecrementValue(PageNum)#&a=horsham_exports" style="color:##FFFFFF">&lt;&lt;&nbsp;Previous</A></CFOUTPUT>
                <A HREF = "##" style="color:##FFFFFF" onClick="alert('This is the first record')">&lt;&lt;&nbsp;Previous</A>
            <TD width="178" align="center">
            <!--- If Next is true, display the previous link. --->
              <cfif Next>
                  <A HREF = "index.cfm?StartRow=#NextStart#&PageNum=#IncrementValue(PageNum)#&a=horsham_exports" style="color:##FFFFFF">Next&nbsp;&gt;&gt;</A>
                <A HREF = "##" style="color:##FFFFFF" onClick="alert('This is the last record')">Next Record</A>
            <TD width="112" align="center">
                <A HREF = "index.cfm?StartRow=#get_products.recordcount#&a=horsham_exports" style="color:##FFFFFF">Last Record&nbsp;&gt;&gt;</A>            </CFOUTPUT>
        <table width="467" height="40" border = "0" align="center" cellpadding="3" cellspacing="1" bgcolor="cccccc">
          <tr bgcolor="#19569B" style="color:#FFFFFF;font-weight:bold">
            <td width="141" align="center" bgcolor="#FFFFFF" style="color:##FFFFFF"><label>
              <input name="Add New" type="submit" id="Add New" value="Add New Product" />
            </label>        </td>
            <td width="179" align="center" bgcolor="#FFFFFF"><label>
              <input name="Update" type="submit" id="Update" value="Update Product Details" />
            <td width="125" align="center" bgcolor="#FFFFFF"><label>
              <input type="submit" name="Submit3" value="Submit Changes" />
        <table width="720" cellpadding="3" align="center">
            <td width="285" valign="top">
              <table width="100%" cellspacing="0" cellpadding="3" bgcolor="cccccc" align="center">
                <tr bgcolor="ffffff">
                  <td valign="top"><a href="#" onClick="alert('This form is used for entering all for products being exported outside the U.K. from the Horsham Site.')" class="link1">For More Information - Click Here</a></td>
                <tr bgcolor="ffffff">
                  <td valign="bottom" height="25"><img src="images/logo.jpg" border="0"></td>
            <td width="285" valign="top">
              <table width="100%" cellspacing="1" cellpadding="3" bgcolor="cccccc">
                    <tr class="large_white" bgcolor="19569B">
                        <td colspan="2">PRODUCT SEARCH</td>
                    <tr bgcolor="ffffff">
                        <td width="100">Product Code:</td>
                        <td><input type="text" class="cellbox"  name="productcode" size="15">&nbsp;<input type="submit" value="Go"></td>
            <td width="150" valign="top">
              <table width="100%" cellspacing="1" cellpadding="3" bgcolor="cccccc">
                    <tr class="large_white" bgcolor="19569B">
                        <td colspan="2">OPTIONS</td>
                    <tr bgcolor="ffffff">
                        <td width="65" align="center"><input type="button" onClick="javascript:self.location='horsham.cfm?a=menu'" value="Menu"></td>
                        <td width="74" align="center"><input type="button" onClick="javascript:self.location='horsham.cfm?a=menu'"  value="Close"></td>


     <cfquery  name="get_shipping" datasource="dt446">
        select * from tblhorsham_exports_pack_details where productcode = '#session.productcode#'
      <table align="center" width="3000" cellspacing="1" cellpadding="3" bgcolor="cccccc">
        <tr bgcolor="f6f6f6">
      <cfloop query="get_shipping">
        <tr class="small_black" bgcolor="<cfif currentrow mod 2>##FFFFFF<cfelse>##E6E6E6</cfif>">
          <td width="80">#left(Date_From,10)#</td>
          <td width="80">#left(Date_To,10)#</td>

    I expect to filter the data through to a savechanges.cfm file which later inserts the data into the tables.

    I am not sure how i can make the buttons work on the page to serve their task.

    I am doing as part of a project at college, thus the urgency.

    Thanks for all your help!

    LVL 9

    Expert Comment

    Hmmm I'll take a look at your code, but hopefully someone else will step in on this.  There is going to have to be some javascript functions to communicate between the parent and child areas, and then some display changes based on what is happening in each (view/edit/add).  It definitely doesn't look to me like it's an easy solution, but maybe someone else has more experience with this kind of iframe interaction.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    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

    Suggested Solutions

    Title # Comments Views Activity
    MySQL with ISAPI 2 42
    Problem to Eclipse 16 86
    htaccess restrict subdomain 4 53
    Configure IIS to process JSON 10 47
    A web service ( is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
    In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    737 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