Link to home
Start Free TrialLog in
Avatar of aneilg
aneilgFlag for United Kingdom of Great Britain and Northern Ireland

asked on

java validation

i cannot get my java validation to fire.

help please.
<script type="text/javascript">
    var _validFileExtensions = [".jpg", ".jpeg", ".bmp", ".gif", ".png"];

    function Validate(oForm) {
        var Inputs = document.getElementById("FileUpload");
        var blnValid = false;
        var sCurExtension = "";
        var sFileName = document.getElementById("file").value;
        for (var j = 0; j < _validFileExtensions.length; j++) {
            sCurExtension = _validFileExtensions[j];
            if (sFileName.substr(sFileName.length - sCurExtension.length, sCurExtension.length).toLowerCase() == sCurExtension.toLowerCase()) {
                blnValid = true;
                break;
            }
        }

        if (blnValid == false) {
            alert("Sorry, " + sFileName + " is invalid, allowed extensions are: " + _validFileExtensions.join(", "));
            return false;
        }

    }
</script>

Open in new window


<body>
<form onsubmit="return Validate(this);">

    <div id="upload-choices">
        <div class="editor-row">
            <div class="editor-label">
                <label>Select image</label>
            </div><div class="editor-field">
                <input type="file" name="file" id="file" multiple="multiple" accept="image/*" required="required" title="Please choose at least one file" />
            </div>
        </div>

        <div class="editor-row">
            <div class="editor-label">
                <label>Add Notes</label>
            </div><div class="editor-field-notes">
                <input type="text" name="txtimageNotes" id="imageNotes"  />
            </div>
        </div>
        
        <div class="editor-row">
            <div class="editor-label">
                <label>Upload image</label>
            </div><div class="editor-field">
                <input type="Submit" name="FileUpload" id="FileUpload" value="Upload image" onclick="Validate" />
            </div>
        </div>
    </div>
</form>
</body>

Open in new window


thanks
ASKER CERTIFIED SOLUTION
Avatar of sivagnanam chandrakanth
sivagnanam chandrakanth
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aneilg

ASKER

perfect. thanks so mush.

live long and Prosper.

thanks again.
Avatar of aneilg

ASKER

thanks.