This question is locked. New answers and comments are not allowed.
Hello,
A slightly odd one here!
I have a textarea to allow the user to submit a comment. Once a comment is submitted, I use JavaScript to confirm the comment with an alert on screen and use $('#newComment').val(''); to empty the textarea so that another comment can be made. Here is the form code:
However - although after the first comment is made, if without navigating away the user just hits the post button again without entering any more text, then the text from the first comment is posted.
I've proved that with this code, where both on initial submission and also second time - with an APPARENTLY empty text area - the first alert says "undefined" but the second alert contains the text from the first comment.
Any pointers, please?
Thanks, Stewart :)
A slightly odd one here!
I have a textarea to allow the user to submit a comment. Once a comment is submitted, I use JavaScript to confirm the comment with an alert on screen and use $('#newComment').val(''); to empty the textarea so that another comment can be made. Here is the form code:
<
div
id
=
"commentBox"
>
<
div
style
=
"text-align: left;"
>Your comment:</
div
>
<
textarea
data-bind
=
"value: comment"
id
=
"newComment"
rows
=
"3"
style
=
"background-color: #FFFFFF; border-style: solid; border-width: 1px; width: 98%"
>
</
textarea
>
<
div
class
=
"buttonArea"
>
<
a
id
=
"postcomment"
data-role
=
"button"
data-bind
=
"click: onPostComment"
class
=
"login-button"
style
=
"background-color: #f0f0f0; colour: green"
>Post</
a
>
</
div
>
</
div
>
However - although after the first comment is made, if without navigating away the user just hits the post button again without entering any more text, then the text from the first comment is posted.
I've proved that with this code, where both on initial submission and also second time - with an APPARENTLY empty text area - the first alert says "undefined" but the second alert contains the text from the first comment.
alert(comment);
var that = this,
comment = that.get('comment').trim();
alert(comment);
Any pointers, please?
Thanks, Stewart :)