0

I want to use the value of textarea present within a template. My code is as below:

<tr>
  <td style="background-color:#ffffff; padding:40px 22px; font-family:Arial, Helvetica, sans-serif; color:#505050; font-size:12px; font-weight:normal;">
    **[[NEWSLETTER_BODY]]**
  </td>
</tr>

I want to use the value from the Javascript function below at the place [[NEWSLETTER_BODY]]. Can you help me in this regard? Thanks in advance.

{literal}
<script language="javascript" type="text/javascript">
function get_text_area_value(){ 
  var email_body = jQuery("textarea#newsletter_email_body").val();
  //alert(email_body);
}
</script>
{/literal}

Actually I want to call this function in following fashion. At the same time the value should be there in the smarty template.

<input type="button" name="btn_preview" id="btn_preview" value="{$preview_value}" class="submit" id="preview_newsletter" onclick="get_text_area_value()">

1 Answer 1

1

The contents of the newsletter will have to be submitted to the server in order for them to be available to Smarty. Since you'll need to submit anyway, you won't need to do anything special - just submit the form using the submit button you already have.

If you don't want to submit the form, but prefer to show the contents of the textarea somewhere else on the page and properly formatted, then you won't need Smarty. Instead, use JavaScript to grab the textarea contents (you already have that code) and append the contents to a element somewhere else, e.g.

var email_body = jQuery("textarea#newsletter_email_body").val();
$("mydiv").innerHTML = email_body;

You may need to sanitize the HTML contents of the textarea first.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.