0

I have a pretty simple html file with a validation function in javascript that I am trying to make execute when the form is submitted. However, I can not get the is_checked() function to run as evidence by no console log statements being executed. I am using Eclipse and an Apache TomCat 7 server which is properly executing all jsp, servlet, and html code but no javascript.

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Example</title>
<script type="text/javascript">
function is_checked() { 
    console.log("is_checked() was called");
    var taskChecked = document.getElementByID('task').checked;
    var projectChecked = document.getElementByID('project').checked;
    var autoChecked = document.getElementByID('auto').checked;
    var manualChecked = document.getElementByID('manual').checked;

    console.log("taskChecked " + taskChecked);
    console.log("projectChecked " + projectChecked);
    console.log("manualChecked " + manualChecked);
    console.log("autoChecked " + autoChecked);


    if((taskChecked === "true" || projectChecked === "true") 
     && (autoChecked === "true" || manualChecked === "true")) {
        return true;
    } else {
        alert('Must select task or project and either auto or manual!');
        return false;
    }
}
</script>
</head>
<body>
<form action="#" onsubmit="return is_checked()" method="post">
<table>
    <tr>
      <td>Process Level: </td>
      <td>
       <input type="radio" name="process" value="task" id="task">Task
      </td>
      <td>
         <input type="radio" name="process" value="project"
          id="project">Project
    </td>
    </tr>
    <tr>
        <td>Method Type: </td>
        <td>
         <input type="radio" name="method" value="auto" id="auto">Auto
       </td>
        <td>
         <input type="radio" name="method" value="manual" 
             id="manual">Manual
      </td>
    </tr>
    <tr>
        <td colspan="2">
            <textarea name="ids" rows="15" cols="10"></textarea>
        </td>
    </tr>
    <tr>
        <td>
         <input type="submit" value="Submit">
       </td>
    </tr>
</table>
</form> 
</body>
</html>
2
  • why do you have is_checked() function in the form tag and in the submit tag? its doing it twice; just have it in the form tag. Commented Mar 17, 2015 at 17:11
  • I tried both methods and just forgot to remove it when I copied the code into the textarea. It is my understanding that onsubmit is what should be used in the form tag. Commented Mar 17, 2015 at 17:17

1 Answer 1

1

You have a typo: document.getElementByID should be replaced with document.getElementById

Btw, you are calling the function twice, you can remove the onClick in the submit input

Sign up to request clarification or add additional context in comments.

1 Comment

Wow If I had enough points to down grade my own question I would. The ID instead of Id was the problem. Thanks for the close eye on that one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.