Javascript access to Product Variables in an HTML scriptlet
Javascript access to Product Variables in an HTML scriptlet
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.
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.
Re: Javascript access to Product Variables in an HTML scriptlet
Following script is working for me on product details page.
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.
Code: Select all
<script language='javascript' type='text/javascript'>
alert('$Product.Name');
</script>
- 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
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()
<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
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
Re: Javascript access to Product Variables in an HTML scriptlet
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);
- 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
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
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
Re: Javascript access to Product Variables in an HTML scriptlet
Mazhar,
The single quotes around the variable reference works.
Thank you very much !!!
The single quotes around the variable reference works.
Thank you very much !!!
Re: Javascript access to Product Variables in an HTML scriptlet
mazhar wrote:Following script is working for me on product details page.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.Code: Select all
<script language='javascript' type='text/javascript'> alert('$Product.Name'); </script>
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?