Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1147
  • Last Modified:

Passing a Null/Zero Form Value in Javascript

I've got a javascript that passes 3 form values into a .bat file, it looks like this:

function runPrintJob() {

  var shell = new ActiveXObject("WScript.shell");
  shell.run("S:/PrintLabel.bat "+frmPSTransactions.Item.value+" "+frmPSTransactions.Lot.value+" "+frmPSTransactions.Serial.value);
}

The problem is that sometimes the Lot.value is null (or zero) and what will happen is that the .bat file will then skip that variable and use the Serial.value (third field) as the Lot.value (second field).

Is there any way of changing this so that there is a pre-defined zero (or nothing) in place of the Lot.value which only gets replaced by the actual value should there one exist?
0
deltex141
Asked:
deltex141
  • 4
  • 2
1 Solution
 
Göran AnderssonCommented:
The value of a form field can not be null. It can be empty ('').

You can replace an empty value with zero, that will keep the arguments in place:

var lot = frmPSTransactions.Lot.value;
it (lot.length == 0) lot = '0';
shell.run("S:/PrintLabel.bat "+frmPSTransactions.Item.value+" "+lot+" "+frmPSTransactions.Serial.value);
0
 
Göran AnderssonCommented:
If a zero actually is a problem also, you can replace them both with something else that the batch file can handle:

it (lot.length == 0 || lot == '0') lot = '-1';
0
 
deltex141Author Commented:
Is the syntax on this correct? I'm getting en error

it (lot.length == 0) lot = '0';

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
deltex141Author Commented:
Specifically, it saying that it "Expected ;" on the

it (lot.length == 0) lot = '0';

Which is off because there is one there
0
 
Göran AnderssonCommented:
Sorry, a typo that I happened to repeat by copying/pasting...

"it" should of course be "if".
0
 
Göran AnderssonCommented:
Checking back to see if you had any progress?
0
 
Computer101Commented:
Forced accept.

Computer101
Community Support Moderator
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now