How do I use script to modify the HTML in an HTML field on a catalog item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2015 08:15 PM
I want to add more HMTL to an HTML field that already has HTML in it.
As my user interacts with a catalog item, I want to add rows to an established table in an HTML control.
The HTML field appears on the catalog item and contains a table (with the heading row).
I want to edit the table using a UI Macro. The user will put text into a single text box and clicks an "Add Row" button placed on the form by a UI Macro field.
When the user clicks the button the UI macro will add a new row to the table in the HTML field.
The problem I'm getting is that although the UI macro can get the text from the single text box and wrap html around it, the result always appears without the HTML.
Here's the UI Macro:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<j:set var="jvar_n" value="add_row_${ref}"/>
<a id="${jvar_n}" onclick="addRow('${ref}')">
<button>add row</button>
</a>
<script>
var HTMlist, newHTMLlist, newTblRow;
function addRow(reference) {
getList();
concatRow();
newHTMLlist = HTMLlist + newTblRow;
g_form.setValue('whole_thing', newList);
g_form.setValue('list', newHTMLlist);
clearRow();
}
function getList() {
HTMLlist = g_form.getValue('list');
}
function concatRow() {
newTblRow = "<tr><td>" + g_form.getValue('name') + "</td><td>" + g_form.getValue('address') + "</td><td>" + g_form.getValue('phone') + "</td></tr>";
}
function clearRow() {
g_form.setValue('name','');
g_form.setValue('address','');
g_form.setValue('phone','');
}
</script>
</j:jelly>
Any suggestions would be greatly appreciated.
Thanks,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2015 08:24 PM
Just a suggestion: Instead of doing so much coding why don't you use Catalog Table Variables:
I think this will serve your purpose.