View Full Version : calling variable from parent document in ajax loaded content

04-20-2012, 10:37 PM
I have a page that sets a global variable with the date, the ajax loaded content requests that date but for some reason is not working.

I use jquery load() to bring the new page into the div and attempt to use an alert(pageDate) to see the date but it's blank...

Any idea's? thanks.

04-21-2012, 03:49 PM
The general situation you describe sounds workable. There are a number of things that could cause the result you're reporting. If you're getting a blank alert, it means that pageDate is declared but not defined at either the time the alert is fired, or perhaps at the time the function that fires it is constructed. That would depend on how the code is written. And that's where the 'number of ways' part comes in.

If you want more help, either put up a demo the shows the problem in action and link us to it, or include in your post code for a top page and an imported page, enough to see the problem if we run it on our machine.

In either case, even if it seems obvious to you, tell us what we have to do (what we have to click, etc.) to see the problem.

04-21-2012, 03:56 PM
This page is loaded into the document... and at the bottom you see it sets the var 'currentDate'.. the alert right below the var shows the current date and fires correctly.

<?php include'../cvars.php'; ?>
<script type="text/javascript" language="javascript">

<div id="ordersMenu" style="border:1px solid #939;">
<a href="#" onclick="getPage('mainArea','orders/orders.php');">View Todays Orders</a> |
<a href="#" onclick="getPage('orderArea2','orders/new_order.php');">Place New Order</a> |
<a href="#" onclick="getPage('orderArea2','orders/view_date.php');">View Orders By Date</a>

<div id="orderArea">
<div id="orderArea2"></div>


$yesterday=strtotime($date . "-1 day");
$tomorrow=strtotime($date . "+1 day");;

echo '<a href="#" onclick="getPage(\'mainArea\',\'orders/orders.php?date='.$yesterday.'\')"><<</a> '.$date.' '.date('l',strtotime($date)).' <a href="#" onclick="getPage(\'mainArea\',\'orders/orders.php?date='.$tomorrow.'\')">>></a>';

getOrders($date); ?>

<script type="text/javascript">
//update current date in javascript
var currentDate='<?=$date?>';



This page is loaded via jquery ".load()" into the div tag id=orderArea2 -the alert fires but is empty...

<?php include'../connectvars.php';
Date: <input type="text" name="orderDate" id="orderDate"><br>
Name: <input type="text" name="orderName" maxlength="50"><br>
Phone: <input type="text" name="orderPh" maxlength="20"><br> Cell ? <input type="checkbox" value="1"><br>

Email: <input type="text" name="orderEmail" maxlength="50"><br>
Notes: <input type="text" name="orderNotes" maxlength="50"><br>
<input type="button" name="addItem" id="addItem" value="Add Item 2 Order" onClick="orderAddItem();"><br>
<script type="text/javascript" language="javascript">
<div id="orderItems" style="padding:5px"></div>

<div id="submitNewOrder" style="margin:5px;"></div>

04-21-2012, 04:39 PM
I would need the code for the includes.


and other functions are undefined.

Or you could link me to the page whose code appears in the first code block in your post.

Or you could give me the served source code of the top page and the imported page (I think that's orders.php).