Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update value in a parent window without refreshing 1

Status
Not open for further replies.

ifx

Technical User
Feb 26, 2002
57
GB
Hi,

Here's the problem:

I've got a shopping system which opens up in a popup window for a user to add a new product. When the product is added the user can close the window and continue shopping on the main 'parent' window.

The parent window shows the number of items in the users basket. However, this will only change if the user refreshes the page, or I use some javascript in the popup that fires a refresh of the parent. I only want to update the value of the number of items in the basket, and not the whole page. Is this possible?

Thanks in advance if you can help!
 
if its a shoopin cart it means session will be used. u cannot modify the session using JS. therefore it is being resubmitted...

Known is handfull, Unknown is worldfull
 
I realise JS doesn't handle sessions - the whole system is developed in ASP. I've written a small file that show the number of items in the basket and writes it out using document.write(). This is called from the parent window as
<script language=&quot;javascript&quot; src=&quot;items.asp&quot;>
which works great.

I suppose what I really need is for the child window to trigger a function in the parent which will cause the javascript to re-read items.asp. Can this be done?

 
why dont you put the basket items on the parent page into an iframe and then refresh that? mind you this is IE only i think. Dont think netscrap can handle iframe

on error goto hell
 
Thanks for your answer.. I did try that, but was a bit worried that Netscape doesn't support it. A big enough proprtion of visitors were on NS to make me reconsider this. I did try this function:
Code:
 <script type=&quot;text/javascript&quot;>
 function UpdateBasket(){
  basket.src = &quot;basketitems.asp&quot;
 }
 </script>
which was supposed to update this tag which was placed in the same page where the number of items should be displayed:
Code:
<script id=&quot;basket&quot; type=&quot;text/javascript&quot; src=&quot;basketitems.asp&quot;></script>

but nothing happened when I triggered the function (although I didn't get an error either)
 
what does basketitems.asp do? is it doing a document.write or is it updating input fields etc ?

on error goto hell
 
wait, does the browser even load basketitems.asp. Surely it wont unless it sees the .js extension, right?

try putting an alert in basketitems.asp and see if it gets fired

on error goto hell
 
Hmm, that's interesting - I put an alert into basketitems.asp and it fired. Only problem is that the value in the page isn't updated.

basketitems.asp simply loops through the session array to see how many products are stored in the users shopping basket. It shouldn't matter whether it has a .js extension - the browser calls it just the same. So I know it's working, just not updating the value on the page. Odd...
 
basketitems.asp returns the line:

document.write('<%=iBasketItems%>');

and the line:

<script id=&quot;basket&quot; type=&quot;text/javascript&quot; src=&quot;basketitems.asp&quot;></script>

writes it to the browser. It's just wont update when I recall the basketitems.asp page using:
Code:
 <script type=&quot;text/javascript&quot;>
 function UpdateBasket(){
  basket.src = &quot;basketitems.asp&quot;
 }
 </script>
But when I added

Code:
alert('this is an alert!');

to basketitems.asp it displayed the alert message when running that function
 
for ie you can put a placeholder such as a span or a div

ie..
FOR IE AND NETSCAPE 6:
<div id=BasketTotal>
</div>

FOR NETSCAPE 4
<INPUT TYPE=TEXT name=&quot;BasketTotal&quot; readonly>

then your script in basketitems.asp would be:

IE:
BasketTotal.innerHTML = &quot;<%=iBasketItems%>&quot;;

NETSCAPE 6:
document.getElementById(&quot;BasketTotal&quot;).innerHTML = &quot;<%=iBasketItems%>&quot;;

For Netscape 4 why dont you use a input text box and make it readonly and put the value in there

document.formName.BasketTotal.value = &quot;<%=iBasketItems%>&quot;;


on error goto hell
 
Ah yes! Exactly what I was looking for! Tried the textbox and it works great! Brilliant, thanks very much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top