Jovan Yong Jovan Yong - 5 months ago 7
Javascript Question

Check for empty field for my username and password

<?php
if ( isset( $_GET['fail']) && !empty($_POST["uname"]))
{
echo '<script language="javascript">';
echo 'alert("Your name or password is incorrect")';
echo '</script>';
}


How do I check for empty field when I press the submit button?

Answer

You could use required attribute of html5 in your input tag as

<input type="text" name="USERNAME" required>
<input type="text" name="PASSWORD" required>

This won't allow to submit form without content in the textbox.

Comments