By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,143 Members | 865 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,143 IT Pros & Developers. It's quick & easy.

Best way to update a value dynamically

P: n/a
I may be posting to completely the wrong newsgroup, but I need to ask.

Basically I have created a shop cart that displays the current running total
in the header of my site so that it appears at the top of every page.

This value is updated when the customer adds to the basket, but the problem
is that this value is displayed before the basket routine calcs what the
running total is which makes it look a little silly as this value is always
out from the basket total when they do any changes.

I want to keep it at the top rather than put it at the bottom where I know
it will work, but I will lose the effect I am trying to create.

So what I'm basically asking is, do you know of a routine that can
dynamically go and change the header value once I have the basket total?

I was going to use .InnerText by putting the header value in a <SPAN
ID=xx>thevalue</SPAN>, but I have a feeling that this isn't as
cross-platform compatible as it should be. Am I right?

Any better ideas?

Rgds

Robbie


Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
DU
Astra wrote:
I may be posting to completely the wrong newsgroup, but I need to ask.

Basically I have created a shop cart that displays the current running total
in the header of my site so that it appears at the top of every page.

This value is updated when the customer adds to the basket, but the problem
is that this value is displayed before the basket routine calcs what the
running total is which makes it look a little silly as this value is always
out from the basket total when they do any changes.

I want to keep it at the top rather than put it at the bottom where I know
it will work, but I will lose the effect I am trying to create.

So what I'm basically asking is, do you know of a routine that can
dynamically go and change the header value once I have the basket total?

I was going to use .InnerText by putting the header value in a <SPAN
ID=xx>thevalue</SPAN>, but I have a feeling that this isn't as
cross-platform compatible as it should be. Am I right?

Any better ideas?

Rgds

Robbie


I think you should just use an <input type="text" name="TotalShopCart"
value=""> for your shopcart total value which value can be dynamically
updated thanks to an onchange event handler on item elements. You can
still use a <span> but that's not the best/ideal element to render
calculated values.

Assuming
<span id="idShopCartTotal">&nbsp;</span>
then

function UpdateShopCartTotal()
{
var Total;
(...) some loop which will cumulate the elements' values in the shop
cart (...)
if(document.getElementById &&
document.getElementById("idShopCartTotal").childNo des[0] &&
document.getElementById("idShopCartTotal").childNo des[0].nodeType == 3)
{
document.getElementById("idShopCartTotal").childNo des[0].nodeValue = Total;
};
}

DU
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.