Jump to content

New custom field based on existing values


MyLama

Recommended Posts

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.

Link to comment
Share on other sites

{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.

Link to comment
Share on other sites

{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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated