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.AlreadyPo sted.value =="NO")
{
frmCOShipping.AlreadyPoste d.value="Y ES"
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.she ll");
shell.run("S:/Scripts/Prin tCatadyneS erialNumbe rLabel.bat "+frmCOShipping.Item.value +" "+frmCOShipping.Serial.val ue);
}
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.AlreadyPoste d?
onSubmit="return checkSubmit()"
and runs the following script:
function checkSubmit()
{
if(frmCOShipping.AlreadyPo
{
frmCOShipping.AlreadyPoste
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.she
shell.run("S:/Scripts/Prin
}
Right now,
onsubmit="if(checkSubmit()
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.AlreadyPoste
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
--
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
Nobody said onsubmit="if(checkSubmit()
Nobody suggested onsubmit="if(checkSubmit()
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()
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
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
--
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
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.
Better yet, delete the question but do *not* refund the points.
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."
"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."
onsubmit="if(checkSubmit()
... 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