Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

JavaScript not being called when form is submitted

Posted on 2007-11-19
2
Medium Priority
?
563 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 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

722 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