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?
LVL 4
deltex141Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Göran AnderssonConnect With a Mentor Commented:
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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