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";
}
4

2 回答 2

3

文本区域值不能为空,只能为空""或非空

var commentsVal = comments.value;
if(commentsVal !== "") {
   document.myForm.action = "?Email";
}
于 2013-11-12T15:33:28.830 回答
2

.val()由 jQuery(可能还有其他框架)使用。如果您使用的是原始 javaScript,则需要使用.value

var commentsVal = comments.value;
if(commentsVal !== "") 
{
     document.myForm.action = "?Email";
}
于 2013-11-12T15:33:19.577 回答