How can you check an empty tag -field by Javascript like in asking questions at SO?
I would not like to pass the user to send a question without specifying the tag.
How can you check an empty tag -field by Javascript like in asking questions at SO?
I would not like to pass the user to send a question without specifying the tag.
To start you off, in your page:
function validateForm()
{
var tags = document.getElementById('tags').value;
if(tags == '' || tags == null) {
alert('Please enter one or more tags');
return false;
}
return true;
}
<form method="post" onsubmit="javascript:validateForm()">
<input type="text" id="tags" name="tags"/>
<input type="submit" value="Post your question"/>
</form>
In your PHP script:
if(isset($_POST['tags']) && !empty($_POST['tags'])) {
$tags = $_POST['tags'];
}