Solved

JavaScript not being called when form is submitted

Posted on 2007-11-19
2
556 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 500 total points
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now