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
  • 233
  • 10
  • 20
  • 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,402
  • 8
  • 50
  • 61
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
  • 217,595
  • 99
  • 455
  • 496