Link to home
Start Free TrialLog in
Avatar of deltex141
deltex141

asked on

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?
ASKER CERTIFIED SOLUTION
Avatar of Badotz
Badotz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of b0lsc0tt
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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
As i already pointed out in my post http:#20375311
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
yes I did:

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

--
Lee
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 https://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
And a split was definitely in order here
Grade B? Was I bad?
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.
Avatar of deltex141
deltex141

ASKER

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.
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."