Reputation: 3
I want to do checking with my textarea where if the user does not fill in the message, it will prompt out an alert message. However my textarea seem like it is replaced by a nicEdit textarea.
<head>
<script type="text/javascript" src="/ecover/common/editor/editor.js"></script>
<script type="text/javascript">
bkLib.onDomLoaded(function() {new nicEditor({fullPanel : true}).panelInstance('MESSAGE');});
function validate()
{
if(document.mainfrm.MESSAGE.value=="")
{
alert("Please enter the value Message");
document.mainfrm.MESSAGE.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<form name="mainfrm" method="post" action="addMessageRep.jsp" onSubmit="return validate();">
<textarea id="MESSAGE" name="MESSAGE" cols="80" rows="20" ></textarea>
</form>
</body>
var isTextarea = (e.nodeName.toLowerCase() == "textarea");
if(isTextarea || this.options.hasPanel) {
var ie7s = (bkLib.isMSIE && !((typeof document.body.style.maxHeight != "undefined") && document.compatMode == "CSS1Compat"))
var s = {width: newX+'px', border : '1px solid #ccc', borderTop : 0, overflowY : 'auto', overflowX: 'hidden' };
s[(ie7s) ? 'height' : 'maxHeight'] = (this.ne.options.maxHeight) ? this.ne.options.maxHeight+'px' : null;
this.editorContain = new bkElement('DIV').setStyle(s).appendBefore(e);
var editorElm = new bkElement('DIV').setStyle({width : (newX-8)+'px', margin: '4px', minHeight : newY+'px'}).addClass('main').appendTo(this.editorContain);
e.setStyle({display : 'none'});
editorElm.innerHTML = e.innerHTML;
if(isTextarea) {
editorElm.setContent(e.value);
this.copyElm = e;
var f = e.parentTag('FORM');
if(f) { bkLib.addEvent( f, 'submit', this.saveContent.closure(this)); }
}
editorElm.setStyle((ie7s) ? {height : newY+'px'} : {overflow: 'hidden'});
this.elm = editorElm;
}
Step for testing:
Upvotes: 0
Views: 2119
Reputation: 100175
to get value of niceEditor textarea, try doing:
var nicInstance = nicEditors.findEditor('MESSAGE');
var messageContent = nicInstance.getContent();
//then check for messageContent
Update::
bkLib.onDomLoaded(function() {new nicEditor({fullPanel : true}).panelInstance('MESSAGE');});
function validate()
{
var nicInstance = nicEditors.findEditor('MESSAGE');
var messageContent = nicInstance.getContent();
//since nicEditor sets default value of textarea as <br>
//we are checking for it
if(messageContent=="<br>") {
alert("Please enter the value Message");
document.mainfrm.MESSAGE.focus();
return false;
}
else {
alert("valid");
}
return true;
}
Demo:: jsFiddle
Upvotes: 1