user1514499
user1514499

Reputation: 771

javascript - Alert not working in IE 8

In my web-application I have added javascript in a jsp file.
The alert message is popping up in Firefox. But the alert window is not working in IE 8. Following is the javascript that I am using.
Can anyone please tell how to make this work in IE 8?

 function doSubmit() {
        var checkbox = document.getElementById("terms");
        if (!checkbox.checked) {
          alert("error message goes here.");
          return false;
      } else {
      return true;
      }
    }

Upvotes: 0

Views: 9890

Answers (1)

Shouvik
Shouvik

Reputation: 11730

Works fine, here is how you use it!

<html>

<head>
<script type="text/javascript">

    function doSubmit() {
        var checkbox = document.getElementById("vehicle");
        if (!checkbox.checked) {
          alert("error message goes here.");
          return false;
      } else {
        return true;
      }
    }

</script>
</head>

<body>

    <form name="frm1" onsubmit=" return doSubmit()">
        <input type="checkbox" name="vehicle" value="Bike" />Checked<br />
        <input type="submit" value="Submit" />
    </form>

</body>
</html>

added correction as suggested.

Upvotes: 1

Related Questions