I have a form with the target="_blank", and onsubmit="return validateForm()", as well as a textarea named "wordList". Here is my validateForm() function
function validateForm() {
var x = document.forms["form1"]["wordList"].value;
if (x == null || x == "") {
alert("Word list cannot be empty.");
return false;
}
}
This works fine to test for an empty input, however I need to also verify that the wordList has a minimum number of lines of text. I have tried inserting a php block after this if statement, but by calling 'explode()', it ends up opening a new tab regardless of if there is input or not. Here's what I mean:
function validateForm() {
var x = document.forms["form1"]["wordList"].value;
if (x == null || x == "") {
alert("Word list cannot be empty.");
return false;
}
<?php
$wordInput = explode("\n", str_replace("\r", "", $_POST['wordList']));
?>
}
I'm not sure how to reference the wordList in the php block when it's on the same page, but either way, whenever I click a submit button, even with an empty textarea, it opens the current page in another tab.
Is there a better way than using php to count and validate the number of lines in the text area?