Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

JavaScript not being called when form is submitted

Posted on 2007-11-19
2
Medium Priority
?
565 Views
Last Modified: 2008-02-01
I have a form where I want to put some javascript in to validate the form.  I tried by putting the onsubmit on the form tag and also on the submit button but neither invokes the javascript.  I can't figure out what I'm doing wrong.  Here is the code:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>My Page</title>
<link rel="stylesheet" href="StyleSheet.css" type="text/css" title="hires"/>
<script type="text/javascript">
<!--
function validateForm(theForm)
{
      alert("here");
      return false;
}
//-->
</script>

</head>

<body >
    <table width="100%"  border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td><img src="../graphics/logo.png" width="600" height="128"></td>
      </tr>
      <tr>
        <td class="header"><div align="center">History </div></td>
      </tr>
      <tr>
        <td><hr></td>
      </tr>
      <tr>
        <td class="header"><div align="center">Step 1 - Choose Person</div></td>
      </tr>
        <tr>
          <td>&nbsp;</td>
        </tr>

      <form name="myform" method="post" action="History.asp?step=1" onSubmit="return validateForm(this);">
        <input type="hidden" name="SID" value="252190002">
        <tr>
        <td class="menu"><br>
              <div align="center">
            <p>
              <select name="from" size="10" multiple class="listcontent" id="from">
                <option value="0">All Selections</option>
               
                <option value="1">Doe, Jose</option>
               
                <option value="2">Smith, Deborah</option>
               
              </select>
                  </p>
          </div>
            </td>
      </tr>
        <tr>
          <td class="menu" align="center"><input name="submit" type="submit" id="submit" value="Submit" onSubmit="return validateForm(this);"></td>
        </tr>
        <tr>
          <td class="menu" align="center"><input name="Cancel" type="submit" id="Cancel" value="Cancel"></td>
        </tr>
        </form>

    </table>
</body>

</html>
0
Comment
Question by:dyarosh
2 Comments
 
LVL 4

Accepted Solution

by:
rallsaldo earned 1500 total points
ID: 20315227
Hi,

If I paste your code into a file and run it, the JavaScript does fire. Have you got JavaScript enabled in your browser?

R
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20315819
dyarosh,

Remove the onsubmit event in the Submit button's input tag.  It doesn't belong there.  If you still have a problem then is any other script run by pressing the button or in the form's onsubmit event?  Another script error would cause what is happening.

Let me know if you have any questions or need more information.

b0lsc0tt
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question