This topic is locked
[SOLVED]

 Passing Smarty variable to javascript function

11/5/2007 6:58:59 PM
PHPRunner General questions
F
Fawaz author

I have this field {$row.1clientNote_value} which is a tinytext.
Instead of presenting this field as text area, I want to present it as a hint for a note icon (simply, image and onMouseOver event I want to display the note)
I am using this script:

http://www.dynamicdrive.com/dynamicindex16/showhint.htm
And in the ...._list.php I am using the follwoing code:

<IMG src="include/img/icons/notes.gif" class="hintanchor" onMouseover="showhint('{ldelim}$row.1clientNote_value{rdelim}', this, event, '200px')"> &nbsp;


But showhint function is displaying {$row.1clientNote_value} rather than the actual value.
How do I fix this?
Thanks

Fawaz

J
Jane 11/6/2007

Fawaz,
try to add curly brackets to $row.1clientNote_value variable:

<IMG src="include/img/icons/notes.gif" class="hintanchor" onMouseover="showhint('{ldelim}{$row.1clientNote_value}{rdelim}', this, event, '200px')"> &nbsp;

F
Fawaz author 11/6/2007

Fawaz,

try to add curly brackets to $row.1clientNote_value variable:


Hi Jane,

The reason that I added {ldelim} and {rdelim} is to avoid using { and }
But I did what you advised and I got the following error:

syntax error: unrecognized tag: $row.1clientNote_value{rdelim (Smarty_Compiler.class5.php, line 436)


My problem is how can I pass Smarty variable to javascript function.
Thanks

Fawaz

F
Fawaz author 11/6/2007

Okay, I found a solution, instead of passing Smarty variable to javascript function, I tried the following code, inside the javascript function:

{/literal}'{$row.1clientNote_value}' {literal}


But here the value of the note became constant i.e. the last note in the last record, rather than changing for each record and displaying the matched note.
Is this a bug?
Thanks

Fawaz

admin 11/6/2007

You placing the closing tag first.

{literal}'{$row.1clientNote_value}' {/literal}
V
varzock 11/7/2007

Weird, this technique works very well for me. What kind of values you got in that variable?
I'm using:

{literal}

<script language="JavaScript">

alert('{/literal}{$my_smarty_variable}{literal}');

</script>

{/literal}
F
Fawaz author 11/7/2007

Weird, this technique works very well for me. What kind of values you got in that variable?

I'm using:

{literal}

&lt;script language="JavaScript">

alert('{/literal}{$my_smarty_variable}{literal}');

</script>

{/literal}


Varzock. your code is correct, and I sorted it out in my code.

my problem was to pass Smarty variable when I am calling function xxx({$my_smarty_variable}), but I changed it to the way you are writing.
BUT, this code runs on the client machine which means the {$my_smarty_variable} will have the value of the last record rather than a value for each record. any hints?

Thanks

V
varzock 11/8/2007

Fawaz, could you please show some of your PHP code. It would help sorting out the problem <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=23151&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />

I take it you are generating those hint codes dynamically, possibly using {foreach} Smarty-function?

{foreach from=$row item=hint}

<IMG src="include/img/icons/notes.gif" class="hintanchor" onMouseover="showhint('{/literal}{$hint.1clientNote_value}{literal}', this, event, '200px')"> &nbsp;

{/foreach}


which would go through all the rows in $row array (It is an array, isn't it? Or have I misunderstood something <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=23151&image=2&table=forumreplies' class='bbc_emoticon' alt=':)' />

F
Fawaz author 11/8/2007

Fawaz, could you please show some of your PHP code. It would help sorting out the problem <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=23156&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />

I take it you are generating those hint codes dynamically, possibly using {foreach} Smarty-function?

{foreach from=$row item=hint}

<IMG src="include/img/icons/notes.gif" class="hintanchor" onMouseover="showhint('{/literal}{$hint.1clientNote_value}{literal}', this, event, '200px')"> &nbsp;

{/foreach}


which would go through all the rows in $row array (It is an array, isn't it? Or have I misunderstood something <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=23156&image=2&table=forumreplies' class='bbc_emoticon' alt=':)' />


Hi Varzock,

I really don't have any loop in my code:

I only switch to HTML editor in PHPRunner, and then I placed the javascript function and on the specified record I tried to call the tootip function:

{literal}

&lt;script language="JavaScript">

alert('{/literal}{$my_smarty_variable}{literal}');

</script>

{/literal}


So you see, I am not using a loop and for all records I am geting same hint (which is related to the last record)

I believe this happen because I am not storing the value of each record, in the java script so that when I hover on the record I get the tooltip with the matched value.
How do I do this?
Thanks

Fawaz