[ic] Discounts

Peter peter at pajamian.dhs.org
Wed Feb 28 16:29:36 EST 2007


On 02/28/2007 11:41 AM, cblevins at macronet.com wrote:
> I have this in results_buylist.  The popup returns all the info correctly,
> if the search returns just one product.  If multiple items are returned the
> popup displays the info for the last item on the page.  I have searched
> through the list and cannot find anything relating to this particular
> problem. I am using IC 5.5.0-200612100658.  What am I overlooking?
> 
> <script language="JavaScript">
> <!--
> // This is the function that will open the
> // new window when the mouse is moved over the link
> function open_new_window()
> {
> new_window =
> open("","hoverwindow","width=500,height=100,left=10,top=10","toolbar=no,loca
> tion=no,status=no,menubar=no");
> 
> // open new document
> new_window.document.open();
> 
> new_window.document.write("<html><title>Best Price for
> [item-code]</title>");
> new_window.document.write("<body bgcolor=\"#FFFFFF\">");
> 
> new_window.document.write("<table><tr>[if discount [item-code]]<TD
> ALIGN=right valign=\"top\">[L]Regular price[/L]
> <STRIKE>[item-price]</STRIKE><br><B>[L]Your price[/L]: [price discount=1
> code="[item-code]"]<br>[L]You save[/L]: [currency][calc][item-price
> noformat=1] -  [price discount=1
> code="[item-code]"noformat=1][/calc][/currency]</TD>[/if]</tr></table>");
> 
> new_window.document.write("<br>");
> new_window.document.write("</body></html>");
> 
> // close the document
> new_window.document.close();
> }
> 
> // This is the function that will close the
> // new window when the mouse is moved off the link
> function close_window()
> {
> new_window.close();
> }
> 
> // -->
> </script>

You could simplify your problem with this...

function foo() {
    alert("[item-code]");
}

...

<a href="#" onclick="foo()">...</a>

which will end up looking like this in the final result:

function foo() {
    alert("bar");
}

...

<a href="#" onclick="foo()">...</a>

...

function foo() {
    alert("baz");
}

...

<a href="#" onclick="foo()">...</a>


What happens is that the page is loaded along with all the javascript by
the browser, and each subsequent definition of foo() overwrites the
last, so by the time any of the links are clicked on there is just one
foo(), the last one and so that is what is displayed.

Your solution is to do something like this:

Before your loop:

function foo(bar) {
    alert(bar);
}

...then inside the loop:

<a href="#" onclick="foo('[item-code]')">...</a>


Peter


More information about the interchange-users mailing list