Running a Javacript if Another Script Returns True

I have a web form where I'd to like combine 2 different javascripts where the second runs only if the first returns true (out of true or false)  the first one is activated by

onSubmit="return checkSubmit()"

and runs the following script:

function checkSubmit()
{      
      if(frmCOShipping.AlreadyPosted.value=="NO")
      {                        
            frmCOShipping.AlreadyPosted.value="YES"
            return true;
      }
      else
      {
            return false;
      }      
}


The Second is activated by

onSubmit="runPrintJob(this)"

and runs the following script

function runPrintJob() {

  var shell = new ActiveXObject("WScript.shell");
  shell.run("S:/Scripts/PrintCatadyneSerialNumberLabel.bat "+frmCOShipping.Item.value+" "+frmCOShipping.Serial.value);
}


Right now,

onsubmit="if(checkSubmit() == true) {runPrintJob(this)}">

Runs the second as long as the first returns either true of false, how do i change it to run runPrintJob only if the first one does not return a false on frmCOShipping.AlreadyPosted?
LVL 4
deltex141Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
BadotzConnect With a Mentor Commented:
Run the 2nd function from the 1st:

function checkSubmit()
{      
      if(frmCOShipping.AlreadyPosted.value=="NO")
      {                        
            frmCOShipping.AlreadyPosted.value="YES"
           
            runPrintJob();
             
            return true;
      }
      else
      {
            return false;
      }      
}
0
 
b0lsc0ttIT ManagerCommented:
If you can the method Badotz suggested is the best way to do this.  However your script looks good too.  You could try using just ...

onsubmit="if(checkSubmit()) {runPrintJob(this)}">

... but that should only do runPrintJob if it is true.  I would suggest the problem is some other error or your If in checkSubmit isn't working the way you expect.  Add some alerts to troubleshoot it.  Let me know if you need some suggestions of how to do it but I'll probably need more of the script.  The basic idea of what you are doing is good though and I can't see an error (or reason for runPrintJob to be run both times) in the snippets you did provide.

Let me know if you have a question or need more info.

bol
0
 
Michel PlungjanConnect With a Mentor IT ExpertCommented:
So if Badotz suggests works for you, I'd say points to him
However do you need the form to submit at all or is it just a placeholder for the fields needed for the run?


function runPrintJob(theForm) {
  if (theForm.AlreadyPosted.value=="YES") {
    alert('Already running')
    return false
  }
  theForm.AlreadyPosted.value="YES"

  var shell = new ActiveXObject("WScript.shell");
  shell.run("S:/Scripts/PrintCatadyneSerialNumberLabel.bat "+theForm.Item.value+" "+theForm.Serial.value);
  return true; // submits the form - return false here to just run the shell.run
}

and have


onSubmit="return runPrintJob(this)"
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LeeKowalkowskiCommented:
onsubmit="if(checkSubmit()) {runPrintJob(this)}" doesn't return anything, therefore the submit event is not blocked.  It needs to be onsubmit="if(checkSubmit()) runPrintJob(this); else return false;"

--
Lee
0
 
Michel PlungjanIT ExpertCommented:
As i already pointed out in my post http:#20375311
0
 
LeeKowalkowskiCommented:
You did?

Nobody said onsubmit="if(checkSubmit()) {runPrintJob(this)}" doesnt return anything.  This is why I think the author thinks it "Runs the second as long as the first returns either true [or] false" - because the form will be submitted unless onsubmit returns false.

Nobody suggested onsubmit="if(checkSubmit()) runPrintJob(this); else return false;" before, and I was only suggesting it as a correction to http:#20371379.

As it stands, I prefer Badotz's solution as I think it minimizes the code in an onsubmit attribute ("return checkSubmit()") - If you're going to use inline event handlers, it's absolutely a good idea to limit them to a single function call to keep the implementation contained.

I was only explaining why the author's attempt at onsubmit="if(checkSubmit() == true) {runPrintJob(this)}" would not work for them.

It looks to me that the author would like the form to be submitted, because checkSubmit() only prevents a double-click submission from what I can tell, but you never know...

--
Lee
0
 
Michel PlungjanIT ExpertCommented:
yes I did:

 return true; // submits the form - return false here to just run the shell.run
0
 
LeeKowalkowskiCommented:
Yes, you said that, but that is not what I was saying!

--
Lee
0
 
b0lsc0ttIT ManagerCommented:
Please post and explain why you closed this question as you did.  The B grade makes me wonder if you got the solution or answer.  However there were a number of good posts with info to help.  Also you never commented so it seems odd that you would give a B grade.  Please respond.

If you'd like info on what the grades mean and some guidelines on grading then look at http://www.experts-exchange.com/help.jsp#hi97 .  Your grading history seems unusually harsh.  I hope it doesn't really reflect the help you have received here since it isn't typical.  I'm glad we could help but the closing of this needs an explanation.  If it was an accident then let me know and I can help fix it.

b0lsc0tt
EE Zone Advisor
0
 
Michel PlungjanIT ExpertCommented:
And a split was definitely in order here
0
 
BadotzCommented:
Grade B? Was I bad?
0
 
BadotzCommented:
Since deltex141 does not care to comment, I say award the points as you see fit, modus_operandi.

Better yet, delete the question but do *not* refund the points.
0
 
deltex141Author Commented:
The split was in order since it was a placeholder as mplugian suggested. It was christmas time, relax guys. Badotz, the suggestion to delete the question was NOT appreciated, calm down.
0
 
BadotzCommented:
Nice that the Asker finally responded:

"The split was in order since it was a placeholder as mplugian suggested. It was christmas time, relax guys. Badotz, the suggestion to delete the question was NOT appreciated, calm down."
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.