|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Colored Smarties Smarty n00b
Joined: 03 Jan 2014 Posts: 3
|
Posted: Fri Jan 03, 2014 9:54 pm Post subject: Strange thing about variable, cat and javascript |
|
|
The following code creates a list, which is done by loops, and parts of it should be manipulated by javascript. Therefore I need an individual ID with every loop, so that only some parts are manipulated. That ID comes from the variable "OptionTopID". The "OptionTopID" is concatenated with the variable "optionTopNumber", so that I get a combination of text and number. The concatenated "OptionTopID" then is transmitted to the javascript function "Write Value". But now I have a strange problem with the transmission. The alert in the "WriteValue" function only displays the none-concatenated value "optionTop" without the number. Why? If the number isn't transmitted to the javascript function, the whole thing doesn't work. Do you have any idea why ID is transmitted in the none-concatenated version?
HTML with Smarty:
Code: |
{block name="frontend_index_header_javascript_jquery" append}
<script type="text/javascript" src="{link file='frontend/_resources/javascript/project.js'}"></script>
{/block}
{assign var='optionTopNumber' value=1}
{foreach from=$sArticle.sConfigurator item=sConfigurator}
{assign var='optionTopID' value='optionTop'}
{$optionTopID|cat:$optionTopNumber}
<div {if $configValue.selected}selected="selected"{/if} value="{$configValue.optionID}" class="option_config_top" id="{$optionTopID}">
{$configValue.optionname}{if $configValue.upprice} {if $configValue.upprice > 0}{/if}{/if}
</div>
{foreach from=$sConfigurator.values item=configValue}
<option value="{$configValue.optionID}" class="option_config" onclick="WriteValue('{$configValue.optionname}', '{$optionTopID}')">
{$configValue.optionname}{if $configValue.upprice} {if $configValue.upprice > 0}{/if}{/if}
</option>
{/foreach}
{assign var='optionTopNumber' value=$optionTopNumber+1}
{/foreach}
|
javascript:
Code: |
function WriteValue (obj, id) {
alert(id);
$("#" + id).text(obj);
$("#" + id).slideUp("slow");
};
|
|
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
|
Back to top |
|
Colored Smarties Smarty n00b
Joined: 03 Jan 2014 Posts: 3
|
Posted: Sat Jan 04, 2014 11:07 am Post subject: |
|
|
Thanks. But when I use that solution, then the javascript function doesn't work. There's no alert anymore. I don't know why.
Update: If I change the javascript function like you can see below, than there's the alert "undefined".
Code: |
function WriteValue (obj, id) {
alert(id);
$("#" + id).text(obj);
$(".option_config").slideUp("slow");
};
|
|
|
Back to top |
|
Colored Smarties Smarty n00b
Joined: 03 Jan 2014 Posts: 3
|
Posted: Sat Jan 04, 2014 11:37 am Post subject: |
|
|
I solved the problem. I shouldn't have used "id" for a javascript-variable. If I change it to something else, it works. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|