Hi,
I want check (via javascript), whether the text-field is left empty and throw an error, if its empty?
Any hints where to put the apropriate javascript code?
Thanks!
I want check (via javascript), whether the text-field is left empty and throw an error, if its empty?
Any hints where to put the apropriate javascript code?
Thanks!
RE: Checking if empty - any solutions?
<script language="javascript">
function Validate()
{
if ( window.frames[0].objContent.DOM.body.innerText.length == 0 )
{
alert( 'The field X is required, please verify' ) ;
return false ;
}
return true ;
}
</script>
And set the onsubmit of your form to something like this:
<form onsubmit="return Validate();">
I hope it helps you. Best regards,
FredCK
Frederico Knabben
CKEditor Project Lead and CKSource Owner
--
Follow us on: Twitter | Facebook | Google+ | LinkedIn
RE: Checking if empty - any solutions?
RE: Checking if empty - any solutions?
<script language="javascript">
function Validate(instancename)
{
if ( formname.instancename.value == '')
{
alert( 'The field X is required, please verify the instance: ' + instancename ) ;
return false ;
}
return true ;
}
</script>
And set the onsubmit of your form to something like this:
<form onsubmit="return Validate('instacename');">
I hope it helps you.
RE: Checking if empty - any solutions?
The earlier code accessing the IFRAME's DOM tree does work but has the problem that it doesn't detect if you've switched to the Source view.
I figured out that what you need to do is call setFieldValue() in de IFRAME that contains the editor.
In fact I added a getValue() function to the JavaScript version of the FCKEditor object, like this:
FCKeditor.prototype.getValue = function()
{
document.frames['frame_' + this.InstanceName].setFieldValue();
return parent.document.getElementsByName(this.InstanceName);
}
and added this line:
name="frame_' + this.InstanceName + '"
to the IFRAME generating code in the Create() function.
In the JavaScript code of your page you now only have to do oFCKEditor.getValue() to retrieve the current value of the field. NB: If the field was in Source mode it will be set to HTML mode again because that's a side-effect of the setFieldValue() function.
RE: Checking if empty - any solutions?
return parent.document.getElementsByName(this.InstanceName)[0].value;