I'm trying to do an immediate check on the file extension before uploading it and show a message that if the extension is not allowed (only PDF is allowed) as the following:

Here is the script added to the current PHP page:

```
<script>
    function checkExt() {
        var form_valid = (document.getElementById('fileToUpload').value= "PDF");
        if(!form_valid) {
            alert('only PDF are allowed');
            return false;
        }
        return true;
    }
</script>

```

And here is the form in the body (please not that if an extension is not allowed, I want to show a message near to the file upload browsing button without going into the form action):

```
<form onsubmit='return checkExt()' action='AddPlan.php' method='POST' enctype='multipart/form-data' >

    <input type='file' value="PDF" name='fileToUpload' id='fileToUpload' required>

    <input type='submit' value='upload' name='submit' style="float:left" />
</form>

```