0

Basically, I have a page with a "tabbed" div and when a user clicks on one of the tabs there is an .html page loaded into that div. I was wondering is there anyway that I can have a JS function ran on that new data that is loaded from the .load() javascript function.

Here's the function that loads the new data;

    function switchAssetTabContent(tabContext, func, params) {
    $("#ctl00_ContentPlaceHolder1_Overview1_tcAssetAllocation_tpAssetClassPrimary").html('<table width="375px" height="auto" style="min-height: 100px; height: auto; width: 260px;"><tr><td align="center" valign="middle"><img src="/backoffice/Prospects/App360/images/spinwait.gif" /></td></tr></table>');
    var url = "pageFragments/overview/" + tabContext + ".html";
    $("#ctl00_ContentPlaceHolder1_Overview1_tcAssetAllocation_tpAssetClassPrimary").load( url +"?" + (new Date().getTime()), params, updateYesterday );
    }   

the thing is that the data that is loaded is as follows;

<div bgcolor="white" id="ctl00_ContentPlaceHolder1_Overview1_pnlAssetClassAllocation">
    <table cellspacing="0" cellpadding="0" style="width: 375px;" border="0">
    <tr><td
        valign="top"
        style="background-color: white vertical-align: top; width: 175px"
        id="ctl00_ContentPlaceHolder1_Overview1_tdAssetClassChart">
        <div bgcolor="white" style="padding:0" id="AssetClassChartControlDiv" class="chart">
        </div>
        </td>
      <td valign="top">

        <div id="ctl00_ContentPlaceHolder1_Overview1_pnlAssetClassLegend">

          <input type="hidden" value="" name="ctl00xContentPlaceHolder1xOverview1xuwgAssetClassChartLegend" id="ctl00_ContentPlaceHolder1_Overview1_uwgAssetClassChartLegend" />
          <table cellspacing="0" cellpadding="0" border="0" style="overflow: hidden; position: relative;" id="ctl00xContentPlaceHolder1xOverview1xuwgAssetClassChartLegend_main">
              <tr id="ctl00xContentPlaceHolder1xOverview1xuwgAssetClassChartLegend_mr">
                <td align="left" style="vertical-align: top;">
                    <div id="AssetClassChartControl_legend" class="legend">
                    </div>
                </td>
              </tr>
          </table>

        </div>

</td></tr>
</table>

</div>

and i have js functions written on the main page that calls that info that uses the ID's of those now loaded html <div>s and <span>s. Can i just put the .js functions on the included page? I just thought i should only include my js functions in the <head></head> or outside of the <body></body> tags..... any help is greatly appreciated.

8
  • 2
    You're already calling the function updateYesterday when the load request is complete. Commented Mar 26, 2013 at 16:21
  • Your .load() is overwriting the table that was added just before it, are you sure you're loading into the correct place? Commented Mar 26, 2013 at 16:24
  • @Barmar: That table's only content is a <img src="…/spinwait.gif" />, so probably yes. Commented Mar 26, 2013 at 16:28
  • @bfavaretto that is just to append to the url of what is being loaded, do you think that is what is causing my data to now show? I'm only confused because when i just add the HTML of the page called by .load() function onto the site it renders the data perfectly, but when used in confuction with the .load() function via JS nothing is displayed. Commented Mar 26, 2013 at 16:34
  • @Barmar, that is just supposed to be a spinning icon saying something is being loaded is all, it gives the user something to show them the data is being rendered Commented Mar 26, 2013 at 16:34

1 Answer 1

1

If you want to re-run your document.ready() function, you can make it a named function:

function myReadyFunction() { ... }

document.ready(myReadyFunction);

Then you can use it when calling .load():

$("#ctl00_ContentPlaceHolder1_Overview1_tcAssetAllocation_tpAssetClassPrimary").load( url +"?" + (new Date().getTime()), params, myReadyFunction );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.