Solved

JavaScript not being called when form is submitted

Posted on 2007-11-19
2
557 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
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can anyone please tell me why i can not find ID  investorCoolGrid inside the jsp page? 1 20
Input box gone wrong 8 24
HTML5 frame 5 25
PHP Form Calculate Total Price 10 42
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

770 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