We help IT Professionals succeed at work.
Get Started

How to run two javascripts on submittion of form?

evibesmusic asked
Last Modified: 2012-05-12

I am using one form in which I run the first script below when a user clicks the submit button via a 'onclick' event. I run the second script via an 'onsubmit' event in the <form> tag.

I want the first script to run, then only if no alerts are thrown, I want to run the second script.

This is my first script which I am calling via an 'onclick' event when someone presses the submit button:

<script type="text/javascript">
function verifyAction(){
        alert(\'Please fill in the NUID field.\');
        return false;
  if(document.getElementById("firstname").value=="NUID already in use."){
        alert(\'Please provide a valid NUID before continuing.\');
        return false;
  if(document.getElementById("firstname").value=="NUID not in employee database."){
        alert(\'Please provide a valid NUID before continuing.\');
        return false;

If the script above does not return an alert, I'd like to call the following script. I currently am running this in the <form> tag via and 'onsubmit' event.:

gotoStep2 = function(){ // Updates the contents of a div
  var url = 'scripts/users.php';
  var pars={cmd:'users', step:'2'};
  new Ajax.Updater('steps', url, {method:'get', parameters: pars});
Watch Question
This problem has been solved!
Unlock 3 Answers and 13 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE