htmlArea

A directory of browser-based WYSIWYG editors

  MAIN
INDEX
SEARCH
POSTS
WHO'S
ONLINE
LOG
IN

Home: htmlArea 2: htmlArea 2 & 3 archive (read only): htmlArea v2.0 - Add-Ons:
Validating HTMLArea as Required Field


The htmlArea 2 & 3 editors have been discontinued.

We've made these forums available as a read-only reference and knowledge-base for people using or developing editors based on htmlArea 2 or 3.

Anyone who is interested in taking over version 2 or 3 is free to do so. All we ask is that you choose a new name that doesn't have "htmlarea" in it to avoid confusion with this site. We'll even give you a link in the directory to make it easier for people to find you. If you are developing or hosting an htmlArea based-editor under a new name, please submit it to our directory.

 


bgaines
Novice

Jun 12, 2003, 11:35 AM

Post #1 of 6 (5140 views)
Shortcut
Validating HTMLArea as Required Field Can't Post

 Is there a way to validate the HTMLArea control if it is a required field upon saving it to the database? It seems that when I clear out the box, and do a simple javascript alert to display the value in the field, it does not give me an empty string, rather, it gives me what was there before? Thanks
thanks,
Brian


bgaines
Novice

Jun 12, 2003, 12:28 PM

Post #2 of 6 (5131 views)
Shortcut
Re: [bgaines] Validating HTMLArea as Required Field [In reply to] Can't Post

Ok, worked on it and figured it out. Here is what works for me.


Code
// check to make sure that the news body is completed var editor_obj = document.all["_taNewsBody_editor"];  
var editdoc = editor_obj.contentWindow.document;
var contents = editdoc.body.createTextRange().htmlText;

if (contents == "") {
alert("A headline body is required.");
editor_focus(editor_obj);
return false;
}

thanks,
Brian


pabloron
Novice

Mar 18, 2004, 9:55 AM

Post #3 of 6 (4826 views)
Shortcut
Re: [bgaines] Validating HTMLArea as Required Field [In reply to] Can't Post

I've been trying to figure out exactly where to put the code posted above in order to make the htmlArea a required field. Can anyone help?

Thanks,
Paul


Luis
Veteran

Mar 19, 2004, 2:40 AM

Post #4 of 6 (4809 views)
Shortcut
Re: [pabloron] Validating HTMLArea as Required Field [In reply to] Can't Post

In the HEAD section of your textarea's page:

<script>
function Validate() {
editor_updateOutput('YourTextareaName');
if(document.yourFormName.YourTextareaName.value.length == 0 )
{ alert("Editor is empty");
return false;
}
return true;
}
</script>

In your FORM tag:
<FORM name="yourFormName" ACTION="http://yourscripturl" METHOD="post" onsubmit="return Validate();">

Greetings.


Don't give up!!
http://webstationone.com/test/htmlarea


(This post was edited by Luis on Mar 19, 2004, 2:42 AM)


pabloron
Novice

Mar 19, 2004, 9:18 AM

Post #5 of 6 (4796 views)
Shortcut
Re: [Luis] Validating HTMLArea as Required Field [In reply to] Can't Post

Thanks for your reply Luis - I'm still having the same problem- the form submits with the field being empty. I've pasted the pertinent code below. I appreciate any suggestions.

Paul





...

<script>
function Validate() {
editor_updateOutput('strBody');
if(document.create.strBody.value.length<5)
{ alert("Message body is empty.");
return false;
}
return true;
}
</script>
</head>


<body onLoad="document.forms[0].elements[9].focus();">
<form name="create" action="noteHandler.asp" method="post" onsubmit="return Validate();">

<textarea name="strBody" cols="63" rows="7" tabindex="2"></textarea>

<%
response.write "<script language='JavaScript1.2' defer>" & _
"var config = new Object(); " & _
"config.toolbar = [" & _
" ['italic','underline']," & _
" ['OrderedList','UnOrderedList']," & _
" ['forecolor','backcolor']," & _
"];" & _
"config.width = '100%';" & _
"config.height = '125px';" & _
"config.bodyStyle = 'background-color: white; font-family:Verdana; font-size: x-small;';" & _
"config.debug = 0;" & _
"editor_generate('strBody',config);" & _
"</script>"
%>

...


Luis
Veteran

Mar 19, 2004, 11:35 AM

Post #6 of 6 (4793 views)
Shortcut
Re: [Luis] Validating HTMLArea as Required Field [In reply to] Can't Post

Hi Pabloron:

it may be due to IE automatically puts a <P>&nbsp;</P> at the start. I forgot to mention it because I'm taking care in another place in editor.js

Use this modification to ensure it won't submit in that case or if the editor contains only spaces without characters.

<script>
function Validate() {
editor_updateOutput('YourTextareaName');
str=document.yourFormName.YourTextareaName.value;
str = str.replace(/<(.*?)>)/g, '');
str = str.replace(/&nbsp;)/gi, '');
str = str.replace(/\s)/g, '');
if(str.value.length == 0 )
{ alert("Editor is empty");
return false;
}
return true;
}
</script>

I hope this solves your problem.


Don't give up!!
http://webstationone.com/test/htmlarea

 
 
 


Search for (options)