Click to See Complete Forum and Search --> : Access Javascript Function from HTML code


jeffreywhunter
11-25-2002, 12:17 PM
I want to print the value returned by a javascript function directly in the HTML page that calls it. I have a Javascript table and lookup function (which works from a spawned page using downment.write functions).

// UserSKU, Title, Price, UnitShipCost, Taxable, SKU
// 0 1 2 3 4 5

var prodDescriptions = new Array(
new Array( "RBB101","Purple Leopard",39.95 ,0,1,101),
new Array( "RBB102","Rock Star - Purple Leopard",69.95 ,0,1,102),
new Array( "", "", 0.0, 0, 0, 0 )
);

function GetPriceFromSKU( sku )
{
for( var i=0; i<prodDescriptions.length; i++ ) {
if( prodDescriptions[i][5] == sku )
return prodDescriptions[i][2];
}
return 0.0;
}
----------------------
Now I want to print the following statement...

<BODY>
Value for item RBB102 is : GetPriceFromSKU( 101 )
</BODY>

This of course is not correct. I have tried an inline Javascript as follows, but that did not work either...

<BODY>
Value for item RBB102 is:
<script language="JavaScript">
GetPriceFromSku (01);
</script>
</BODY>

I look forward to your reply! If you see this today (11/25/02), I could use the answer right away... jeffreywhunter@wi.rr.com

Jeff...

kateyez44
11-25-2002, 12:44 PM
Value for item RBB102 is:
<SCRIPT language="JavaScript" type="text/javascript">
<!--
document.write(GetPriceFromSku(01));
// -->
</SCRIPT>


This always works for me. Good luck!

jeffreywhunter
11-25-2002, 12:53 PM
That's what I thought... But I get an error - object expected on a line about 10 lines further down in an unrelated section of code if I have the GetPriceFromSKU function as discussed. If I just put document.write('test'); it works fine and puts 'test' in the document.

Any ideas?

kateyez44
11-25-2002, 02:57 PM
What is the code that you get an error on? What is it supposed to do?