loose my mind loose my mind - 1 month ago 6x
Javascript Question

set error message when image is not uploaded

Set error message when user forgets to upload image. i have not found anything most of the errors are uploading errors i want one that lets the user know that they forgot to upload image also i don't want to let the user go tho the next page until the image is uploaded. i have tried using my old code for forgot first and last name but that doesn't seem to work. that is just an example to show you what i use for errors please help

function formValidator() {
var names = document.getElementById('names');

if (isAlphanumeric(names, "Please enter first and last name")) {

<input type="file" name="file3" id="file3" />


I think you're over-engineering a bit here. You can actually rely on attributes of input in HTML5 that can validate or invalidate form submission for you. For example, denoting an input as required and using formvalidate can trigger this automatically.

<form action="" method="post" id="myform">
    <input type="file" name="file3" id="file3" required formvalidate>
    <input type="submit" novalidate>

The browser will insure the input is supplied before allowing the submission. You can also hook into the form's onsubmit handler via javascript if you need to do further validation...

var myform = document.getElementById('myform');
myform.onsubmit = function(e) { /* do some validation on event here */ };