MyLama Posted March 26, 2012 Share Posted March 26, 2012 Hi - We would like to add a new custom field to our client's product details page (clientarea.php?action=productdetails). The new custom field requires concatenating three existing custom fields along with some text. So, the new custom field would be something like: field1.value + 'sometext ' +field2.value+'sometext '+field3.value The existing fields are all text strings. Looking at the clientareaproductdetails.tpl, I'm pretty stumped as to how this can be done. {foreach from=$productcustomfields item=customfield} <div class="col2half"> <p><h4>{$customfield.name}:</h4> {$customfield.value}</p> </div> Can anyone provide some direction for this? Thanks. 0 Quote Link to comment Share on other sites More sharing options...
laszlof Posted March 26, 2012 Share Posted March 26, 2012 {foreach from=$productcustomfields item=customfield} <input type="hidden" id="{$customfield.name}" value="{$customfield.value}" /> {/foreach} <h4>Field Data:</h4><span id="customfieldsval"></span> <script language="javascript"> {literal} $(document).ready(function() { var field1 = $('#[b]customfield1[/b]').val(); var field2 = $('#[b]customfield2[/b]').val(); $('#customfieldsval').html([b]customfield1[/b] + "Some random text here" + [b]customfield2[/b]); }); {/literal} </script> Replace customfield1 and customfield2 with the actual field names. 0 Quote Link to comment Share on other sites More sharing options...
MyLama Posted March 26, 2012 Author Share Posted March 26, 2012 Hi laszlof - Thanks for that. I'll give it a go. 0 Quote Link to comment Share on other sites More sharing options...
MyLama Posted March 27, 2012 Author Share Posted March 27, 2012 {foreach from=$productcustomfields item=customfield} <input type="hidden" id="{$customfield.name}" value="{$customfield.value}" /> {/foreach} <h4>Field Data:</h4><span id="customfieldsval"></span> <script language="javascript"> {literal} $(document).ready(function() { var field1 = $('#customfield1').val(); var field2 = $('#customfield2').val(); $('#customfieldsval').html(customfield1 + "Some random text here" + customfield2); }); {/literal} </script> Replace customfield1 and customfield2 with the actual field names. Hi - It doesn't seem to be getting the vars: {foreach from=$productcustomfields item=customfield} <div class="col2half"> <p><h4>{$customfield.name}:</h4> {$customfield.value}</p> </div> {/foreach} <h4>Custom Field:</h4><span id="customfieldsval"></span> <script language="javascript"> {literal} $(document).ready(function() { var field1 = $('#[b]ANAME[/b]').val(); var field2 = $('#[b]BNAME[/b]').val(); $('#customfieldsval').html("http://domain.com/index.php?name1=" + [b]ANAME[/b] + "&name2=" + [b]BNAME[/b]); }); {/literal} </script> Does not return anything. I tried using field1 and field2 as well: {foreach from=$productcustomfields item=customfield} <div class="col2half"> <p><h4>{$customfield.name}:</h4> {$customfield.value}</p> </div> {/foreach} <h4>Custom Field:</h4><span id="customfieldsval"></span> <script language="javascript"> {literal} $(document).ready(function() { var field1 = $('#ANAME').val(); var field2 = $('#BNAME').val(); $('#customfieldsval').html("http://domain.com/index.php?name1=" + [b]field1[/b] + "&name2=" + [b]field2[/b]); }); {/literal} </script> This returns the text portion of the string, but the vars return as undefined: http://domain.com/index.php?name1=undefined&name2=undefined I thought this might be because it is outside of the $productcustomfields section, but even if I include the code within the loop (repeating it after every other field) I get the same results. 0 Quote Link to comment Share on other sites More sharing options...
MyLama Posted March 27, 2012 Author Share Posted March 27, 2012 Agghh!! I left off {foreach from=$productcustomfields item=customfield} <input type="hidden" id="{$customfield.name}" value="{$customfield.value}" /> {/foreach} from your code. All good now - works great. Thanks again! 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.