I have a page with 4 FCKeditor textareas. I need to validate that each contains something. The validation works on the first instance, but the next instance fails with "growth is undefined." Any advice?
window.onload = function() { var oFCKeditor = new FCKeditor( 'strengths' ); oFCKeditor.BasePath = '/FCKeditor/'; oFCKeditor.ToolbarSet = 'GL-Minimal'; oFCKeditor.Width = '580px'; oFCKeditor.Height = '200px'; oFCKeditor.ReplaceTextarea(); var oFCKeditor = new FCKeditor( 'growth' ); oFCKeditor.BasePath = '/FCKeditor/'; oFCKeditor.ToolbarSet = 'GL-Minimal'; oFCKeditor.Width = '580px'; oFCKeditor.Height = '200px'; oFCKeditor.ReplaceTextarea(); var oFCKeditor = new FCKeditor( 'objectives' ); oFCKeditor.BasePath = '/FCKeditor/'; oFCKeditor.ToolbarSet = 'GL-Minimal'; oFCKeditor.Width = '580px'; oFCKeditor.Height = '200px'; oFCKeditor.ReplaceTextarea(); var oFCKeditor = new FCKeditor( 'comments' ); oFCKeditor.BasePath = '/FCKeditor/'; oFCKeditor.ToolbarSet = 'GL-Minimal'; oFCKeditor.Width = '580px'; oFCKeditor.Height = '200px'; oFCKeditor.ReplaceTextarea(); }
function validator(theForm) { var strengths = FCKeditorAPI.GetInstance('strengths'); if (strengths.GetXHTML(true) == "" || strengths.GetXHTML(true) == null) { alert("Please enter a value for \"Performance Strengths\"."); return (false); } var growth = FCKeditorAPI.GetInstance('growth'); if (growth.GetXHTML(true) == "" || growth.GetXHTML(true) == null) { alert("Please enter a value for \"Targeted Growth Areas\"."); return (false); } var objectives = FCKeditorAPI.GetInstance('objectives'); if (objectives.GetXHTML(true) == "" || objectives.GetXHTML(true) == null) { alert("Please enter a value for \"Priority Performance Objectives\"."); return (false); } var comments = FCKeditorAPI.GetInstance('comments'); if (comments.GetXHTML(true) == "" || comments.GetXHTML(true) == null) { alert("Please enter a value for \"General Comments\"."); return (false); } return (true); }
<form action="appraisal-other.php" method="post" onsubmit="return validator(this)" class="login"> <textarea name="strengths" id="strengths" cols="70" rows="10"></textarea> <textarea name="growth" id="growth" cols="70" rows="10"></textarea> <textarea name="objectives" id="objectives" cols="70" rows="10"></textarea> <textarea name="comments" id="comments" cols="70" rows="10"></textarea> <input type="submit" value="Submit »" class="button" /></p> </form>
Re: JS Validating Multiple Instances
Re: JS Validating Multiple Instances
Re: JS Validating Multiple Instances
What I did for my situation was use the onComplete command to do something like this:
Which completely fixed my problem. Without the loadedB test it would just continue to load instances onto the page.
I would also name your separate instances differently, I don't know if it is mandated, or if it will keep it from working as I haven't tested it, but is just better practice.
Re: JS Validating Multiple Instances
Thanks!
Re: JS Validating Multiple Instances
Thanks for this!! Which I'd found this thread sooner.. I posted another solution, after wracking my brain for hours.
viewtopic.php?f=6&t=12269&p=32148&hilit=+firefox+multiple#p32155
I'm new to FCK, so didn't know about OnComplete until I saw this thread. Much more elegant than my workaround!
Re: JS Validating Multiple Instances
Right now, I'm working on a news item page that will have 0-10 entries being displayed on the page. The administrator doesn't know anything about HTML, and I wanted to have a FCKEditor instance available for each news item. The trouble is, I don' t know ahead of time what the news items' IDs will be and how many of them will be there ahead of time, so I can't go hard coding in anything.
The solution for me was to make a textarea with the class "replace_w_fck" every time I looped through the database results (using PHP) plus one for new entries. When the page loads, the script creates an array of all the textareas that are members of the replace_w_fck class.