0

I am having trouble figuring out if a TextArea is set(In other words if it has a value). I found most of this information by researching it on Google. I would like the action of a form to change when a TextArea has text added. For some reason my code is not working correctly. Could you explain what I need to change? Here is my HTML and Javascript:

HTML:

<form action="?AddToQuote" method="POST" id="myForm">
<textarea cols="75" rows="6" name="comments" class="comments" id="comments">
</textarea></form>

Javascript:

var comments = document.getElementById("comments");
var commentsVal = comments.val();
if(commentsVal !== null) {
document.myForm.action = "?Email";
}
Tigerman55
  • 223
  • 10
  • 18
  • possible duplicate of [how to use javascript change the form action](http://stackoverflow.com/questions/5361751/how-to-use-javascript-change-the-form-action) – jbabey Nov 12 '13 at 15:33

2 Answers2

3

A text area value cannot be null, it can only be empty "" or non-empty

var commentsVal = comments.value;
if(commentsVal !== "") {
   document.myForm.action = "?Email";
}
devnull69
  • 16,004
  • 4
  • 45
  • 57
2

.val() is used by jQuery (and probably other frameworks). If you're using raw javaScript you need to use .value:

var commentsVal = comments.value;
if(commentsVal !== "") 
{
     document.myForm.action = "?Email";
}
John Conde
  • 212,985
  • 98
  • 444
  • 485