How to access values inside javascript from .vm file

313 Views Asked by At

I have list of values available in my velocity template

#set ($allItems = $action.getProduct())
#foreach ($item in $allItems)
    <div class="wrap" id="productName">$item.getProductName()</div>
#end

now I want them to be available in java script code inside a dialog box.

actor.addPanel("Panel 1", "<label for='product'>document.getElementById('#productName')</label>" + "<br>" +  "<input id='dialoginput' type='text' value=''>Input 1</input>" + "<br>" + "<input id='dialoginput1' type='text' value=''>Input 2</input>", "panel-body");

But it is not printing the value of productName. How can I get the value?

1

There are 1 best solutions below

0
On

You are using the string "productName" for all your id's. Use $item.getProductName() in stead:

#set ($allItems = $action.getProduct())
#foreach ($item in $allItems)
    <div class="wrap" id="$item.getProductName()">$item.getProductName()</div>
#end