Hi Rich,
Getting the newline (\n) characters in and out of the form field is not a problem, per se, it's getting them into a variable that will be passed through a JavaScript function and into the form field that is problematic. Let's see if I can illustrate in a clear fashion...
Code Sample:
<script language="JavaScript">
<!--
function setTemplate(text) {
document.email_form.message.value = text;
}
//-->
</script>
<?php
$template[1] = "string of text...";
$template[2] = "string of text...";
$template[3] = "string of text...\n\n";
$template[3] .= "string of text, continued...";
?>
<form>
<input type="radio" name="template" value="1" onClick="setTemplate('<?php echo($template[1]); ?>')"> Template 1
<input type="radio" name="template" value="2" onClick="setTemplate('<?php echo($template[2]); ?>')"> Template 2
<input type="radio" name="template" value="3" onClick="setTemplate('<?php echo($template[3]); ?>')"> Template 3
</form>
|
|
That will only work if the \n newlines in $template[3] are replaced with
's. The reason seems to be that once PHP processes the file and sends it to the browser, the \n characters have already been replaced by their html equivalent, resulting in something that looks like:
onClick="setTemplate('string
rest of string')"
which kills the JavaScript.
The solution I outlined in the second post is the following:
Code Sample:
<script language="JavaScript">
<!--
function setTemplate(text) {
var template = new Array();
template[1] = "string of text...";
template[2] = "string of text...";
template[3] = "string of text...\n\nstring of text continued...\n\n";
document.email_form.message.value = template[text];
}
//-->
</script>
<form>
<input type="radio" name="template" value="1" onClick="setTemplate('1')"> Template 1
<input type="radio" name="template" value="2" onClick="setTemplate('2')"> Template 2
<input type="radio" name="template" value="3" onClick="setTemplate('3')"> Template 3
</form>
|
|
That apparently works because the JavaScript gets to handle the newline characters before the browser tries to interpret it (?). It's just much more limited what I can do with the templates in that fashion...
(edited to simplify the JavaScript examples)
Dan
[This message has been edited by dank (edited 01-10-01@11:14 pm)]