-1

i am working on a small project to grab some html codes stored in mysql, assign using smarty then use jquery to assign the value to a in html. so far i am able to get this working but for jquery is not processing the html codes.

jquery

{literal}
<script>

function code(val){
var id = val;

if (id == 'msg'){
$('#txt_codes').val('{/literal}{$eml_codes}{literal}');}

}
</script>
{/literal}

{$eml_codes} // outputs fine in html but nothing in jquery. if i use regular text rather 
than html codes it works.

//options

<select name="type" onchange="code(this.value)"> 
<option value"msg">MSG</option>
<option value"other">other</option>
</select>

//textarea
<textarea  id="txt_codes"></textarea>

any idea on how i can pass actual html codes?
samjones39
  • 163
  • 1
  • 13
  • For your project, is it necessary to use the smarty tags, or do you just want to assign the values from mysql to the element values? – cssyphus Aug 23 '14 at 15:19
  • hi, i have to use smary tags for the project – samjones39 Aug 23 '14 at 15:20
  • i don't think smarty is the problem here as it output's fine, just that jquery not passing the html codes – samjones39 Aug 23 '14 at 15:20
  • Javascript/jQuery are client-side languages. The server language (PHP, or ASP) will get the values from the database and send them to the web page. Either directly (before the page loads), or [via AJAX (triggered by some event)](http://stackoverflow.com/questions/17973386/ajax-request-callback-using-jquery/17974843#17974843) after the page has loaded. How are you doing this? Can you show your server-side code? – cssyphus Aug 23 '14 at 15:25
  • i know all that, that part is working fine. i did not include that in the question above since that part is working fine.. if u use {$eml_codes} in html i see all the html codes from the database but for some reason jquery is not passing it. jquery does pass regular text though – samjones39 Aug 23 '14 at 15:37
  • can you please remove the negative comment or comment why you left a negative comment. thank you. – samjones39 Aug 27 '14 at 16:18

1 Answers1

0

You must put smarty code in javasript var.

var eml_codes = {$eml_codes};

{literal}

function code(val){
var id = val;
if (id == 'msg'){
$('#txt_codes').val(eml_codes);}

{/literal}
xsinisa
  • 114
  • 7