I am using this to check if fields are empty. The problem is, the error message is never thrown when a field is empty, it allows submission. Is it because I am trying to run onclick and onclientclick on the button? This is my syntax

HTML

<asp:Button ID="main1212" runat="server" Text="Check If JS Works" 
OnClick="DoSomethingDoNothing_OnClick" OnClientClick="return ValidateData();" />


JS

<script type="text/javascript">
function ValidateData() {
    var main1212, dropdownselection, dropdownselection1, field21
    main1212 = document.getElementByID("txt313").value;
    dropdownselection = document.getElementByID("dropdownlist1").value;
    dropdownselection1 = document.getElementByID("dropdownlist11").value;
    field21 = document.getElementByID("txt12").value; 
    if (main1212 == '')
    {
        alert("Error");
        return false;
    }
    if (dropdownselection == '')
    {
        alert("Error");
        return false;
    }
    if (dropdownlist1 == '')
    {
        alert("Error")
        return false;
    }
    if (field21 == '')
    {
        alert("Error");
        return false;
    }}
</script>



EDIT If I open the browser console and press the button that should run my script their are no errors displayed?

Related posts

Recent Viewed