TyneMCE : mandatory fields
Im using TyneMCE and I have 2 fields in my form that I want to be mandatory.
When I use "inst.getBody().innerHTML" in a javascript it works but only for 1 field.
What can I do to make it works for 2 or more fields?
I named the fields in my form field1 and field2
Javascript
if(form.field1.value==""){ alert('This is a mandatory field.'); }
if(form.field2.value==""){ alert('This is a mandatory field.'); }
This does not work
[482 byte] By [
rogernem] at [2007-11-20 8:21:18]

# 4 Re: TyneMCE : mandatory fields
OK see below code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />
<title>Simple example</title>
<!-- tinyMCE -->
<script language="javascript" type="text/javascript" src="./includes/tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
//this is for elm1 see elements and mode value
tinyMCE.init({
theme : "advanced",
language : "en",
mode : "exact",
elements : "elm1",
relative_urls : false,
remove_script_host : false,
invalid_elements : "script,applet,iframe",
theme_advanced_toolbar_location : "top",
theme_advanced_source_editor_height : "550",
theme_advanced_source_editor_width : "750",
directionality: "ltr",
force_br_newlines : "false",
force_p_newlines : "true",
debug : false,
cleanup : true,
cleanup_on_startup : false,
safari_warning : false,
theme_advanced_buttons1 : "bold, italic, underline,numlist,bulllist, indent, outdent,justifyleft, justifycenter, justifyright, removeformat",
theme_advanced_buttons2 : "",
plugin_insertdate_dateFormat : "%Y-%m-%d",
plugin_insertdate_timeFormat : "%H:%M:%S",
plugin_preview_width : "750",
plugin_preview_height : "550",
extended_valid_elements : "a[name|href|target|title|onclick], img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name], , hr[class|width|size|noshade]",
disk_cache : true,
debug : false,
fullscreen_settings : {
theme_advanced_path_location : "top"
}
});
//this is for elm2 element notice that this has no bold button in this way we
//can specify different buttons on different textareas
tinyMCE.init({
theme : "advanced",
language : "en",
mode : "exact",
elements : "elm2",
relative_urls : false,
remove_script_host : false,
invalid_elements : "script,applet,iframe",
theme_advanced_toolbar_location : "top",
theme_advanced_source_editor_height : "550",
theme_advanced_source_editor_width : "750",
directionality: "ltr",
force_br_newlines : "false",
force_p_newlines : "true",
debug : false,
cleanup : true,
cleanup_on_startup : false,
safari_warning : false,
theme_advanced_buttons1 : "italic, underline,numlist,bulllist, indent, outdent,justifyleft, justifycenter, justifyright, removeformat",
theme_advanced_buttons2 : "",
plugin_insertdate_dateFormat : "%Y-%m-%d",
plugin_insertdate_timeFormat : "%H:%M:%S",
plugin_preview_width : "750",
plugin_preview_height : "550",
extended_valid_elements : "a[name|href|target|title|onclick], img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name], , hr[class|width|size|noshade]",
disk_cache : true,
debug : false,
fullscreen_settings : {
theme_advanced_path_location : "top"
}
});
//this function will be called on submit
function myFunc()
{
tinyMCE.triggerSave(); //this will put content back to textareas
elm1 = document.getElementById("elm1");
elm2 = document.getElementById("elm2");
alert(elm1.value);
alert(elm2.value);
return false;
}
</script>
<!-- /tinyMCE -->
</head>
<body>
<a href="example_full.htm">[Full featured example]</a> <a href="example_advanced.htm">[Advanced example]</a> [Simple example] <a href="example_word.htm">[Word example]</a>
<h3>Simple example</h3>
This page shows how to use TinyMCE on a HTML page in the most common and simple way. On this page each TEXTAREA
element gets converted to a editor instance on page load. Notice how TinyMCE tries to match the width and height of the old text area elements. Read more about the features and settings of TinyMCE in the <a href="../docs/index.html">manual</a>.<br /><br />
<textarea id="elm1" name="elm1" rows="10" cols="40">
Some <b>element</b>, this is to be editor 1.
<p>Some paragraph. <a href="http://www.sourceforge.net">Some link</a></p>
<img src="logo.jpg">
</textarea>
<br />
<textarea id="elm2" name="elm2" rows="15" cols="32">
Some <b>element</b>, this is to be editor 2.
<p>Some paragraph. <a href="http://www.sourceforge.net">Some link</a></p>
<img src="dossier.gif">
</textarea>
<br />
<input type="submit" name="save" value="Submit" onclick="return myFunc()" />
<input type="reset" name="reset" value="Reset" />
</body>
</html>
TinyMCE.triggerSave will put content back to textareas.