Solved

JavaScript not being called when form is submitted

Posted on 2007-11-19
2
560 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 4

Accepted Solution

by:
rallsaldo earned 500 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

636 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