The code is a bit long, so this is the problem-part only :
I have a
Contact Us form like this (form action is PHP SELF). The form also has CAPTCHA but i don't show it here (the CAPTCHA is working fine)
- <form action="<?php echo $PHP_SELF; ?>" method="post" onsubmit="return convalidate();" >
-
-
<textarea id="idconmsg" name="conmsg" cols="50" rows="10" wrap="physical" title="Please type your message"
-
onKeyDown="textCounter(this.form.conmsg,this.form.remLen,500);"
-
onKeyUp="textCounter(this.form.conmsg,this.form.remLen,500);"
-
></textarea>
-
<br />
-
<input readonly type=text name=remLen size=3 maxlength=3 value="500"> characters left
Upon submit, it will call javascript function
convalidate which is validating all input before submission. (The function itself is working fine)
And after validation, it will submit to the same page (PHP SELF) which is containing this php code: (i short out the code because it's too long). I pass the textarea content to $conmsg
-
<?php
-
$conmsg=$_POST['conmsg'];
-
?>
After that, I recheck in PHP whether the CAPTCHA is correct. If correct, I will send the email. If false, the PHP will make a variable $flagcapt=0 that indicates the user needs to re-input the CAPTCHA.
So, after PHP, i also have javascript to recapture the PHP variable after submission. (The javascript is called on the
body load event)
This is the javascript code (I short it out because it's too long):
- function conflag()
-
{
-
var jflagcapt="<?php echo $flagcapt ?>";
-
-
if(jflagcapt==0)
-
{
-
var jconmsg="<?php echo $conmsg ?>";
-
alert(jconmsg);
-
document.getElementById('idconmsg').value = jconmsg;
-
}
-
}
Actually I already succeeded
echo the PHP variable
$conmsg and it works. Although with some errors that the line feed characters from textarea is only displayed as whitespace only.
The problem is, i can't get
alert(jconmsg) working. I know that javascript alert can't contain line feed. But, even though I eliminate the
alert(jconmsg), the script still error.
The
document.getElementById('idconmsg').value = jconmsg;
just not working if I type some line feed in the textarea.
But if I type NO LINE FEED at all, it works like a charm.
So, I assume I have misconception on the LINE FEED thing.
What should I do?
Does my explanation clear enough?
Many thanks acoder,