My validate form js is showing empty first time and then it works My validate form js is showing empty first time and then it works

In my code I use a rich text editor. I have a text box set for that editor and have a function in the form to validate the form to be sure nothing is left blank.

When the form is submitted, it always says that the HTML text box is empty, I click the OK button and click save again and it saves. In other words, it has to be saved 2 times in order for it to stop the popup saying it's empty.

What can I do to make it so if it's empty it shows the popup and if something is in the text area it saves?

Here is some of my code:

<form name="myForm" method="post" action="emails" onsubmit="return validateForm()">
<textarea class="ckeditor" name="html_email" required>$html</textarea>
<input type="submit" name="submit" class="btn-success" id="sendme" value="Save Email"/>
</form>

<script>
function validateForm() {
        var x = document.forms["myForm"]["subject"].value;
        var y = document.forms["myForm"]["html_email"].value;
        if (x == null || x == "") {
            alert("You Did Not Enter A Subject Line");
            return false;
        }
        if (y == null || y == "") {
            alert("You Did Not Create The Body Of The E-Mail");
            return false;
        }
    }
</script>

I am using ckeditor.js in order to make it a rich text editor.



from Stackoverflow

Comments

Popular posts from this blog

\\u0000 cannot be converted to text error \\u0000 cannot be converted to text error

How to create @click on select menu in VueJS How to create @click on select menu in VueJS

Using Ts-Standard linting, JSDoc comment at beginning of file triggers "This rule requires the `strictNullChecks` compiler option" error Using Ts-Standard linting, JSDoc comment at beginning of file triggers "This rule requires the `strictNullChecks` compiler option" error