Javascript access to Product Variables in an HTML scriptlet

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
bl108
Ensign (ENS)
Ensign (ENS)
Posts: 3
Joined: Sat Aug 15, 2009 12:51 am

Javascript access to Product Variables in an HTML scriptlet

Post by bl108 » Wed Oct 07, 2009 4:50 pm

Hello,

Is there a way to get Javascript access to product variables in an html scriptlet ?

For example:

<h2>$Product.Name</h2>
...
<script type="text/javascript">
document.write($Product.Name); <- Doesn't work ?
</script>


Thank you.

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Javascript access to Product Variables in an HTML scriptlet

Post by mazhar » Thu Oct 08, 2009 2:44 am

Following script is working for me on product details page.

Code: Select all

<script language='javascript' type='text/javascript'>
alert('$Product.Name');
</script>
Keep in mind one thing that NVelocity variables are available in contexts for example $Product represents current product and is available on product details page. If you try to run same script on category page it wont return any thing because no product is available in that context.

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: Javascript access to Product Variables in an HTML scriptlet

Post by jmestep » Thu Oct 08, 2009 5:44 am

This is a similar question-- How do I passthe productId in the querystring below?
<asp:ImageButton ID="PrintPage" CausesValidation="false" runat="server" Text="Print Page" EnableViewState="false" ImageUrl="~/images/buttons/print-page.gif" OnClientClick="window.open('printproduct.aspx?ProductId=xx','mywindow','width=800,height=600,scrollbars=yes')" />
This is in a conlib and it's picking up the productid OK from the code behind because I can display the produtid in another control using PID.Text = _ProductId.ToString()
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Javascript access to Product Variables in an HTML scriptlet

Post by mazhar » Thu Oct 08, 2009 6:05 am

set OnClientClick in back end code file like

Code: Select all

PrintPage.OnClientClick= string.Format("window.open('printproduct.aspx?ProductId={0}','mywindow','width=800,height=600,scrollbars=yes')",_Product.ProductId);

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: Javascript access to Product Variables in an HTML scriptlet

Post by jmestep » Thu Oct 08, 2009 8:43 am

Thanks, that worked.
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

bl108
Ensign (ENS)
Ensign (ENS)
Posts: 3
Joined: Sat Aug 15, 2009 12:51 am

Re: Javascript access to Product Variables in an HTML scriptlet

Post by bl108 » Thu Oct 08, 2009 12:06 pm

Mazhar,

The single quotes around the variable reference works.

Thank you very much !!!

MMIKAL
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 32
Joined: Thu Mar 11, 2010 9:30 am

Re: Javascript access to Product Variables in an HTML scriptlet

Post by MMIKAL » Wed Jun 16, 2010 1:30 pm

mazhar wrote:Following script is working for me on product details page.

Code: Select all

<script language='javascript' type='text/javascript'>
alert('$Product.Name');
</script>
Keep in mind one thing that NVelocity variables are available in contexts for example $Product represents current product and is available on product details page. If you try to run same script on category page it wont return any thing because no product is available in that context.

Actually the '$Product.Name' in the JavaScript does not work, the same variable works find outside the js in the same page.
Any idea why?

Post Reply