• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1156
  • 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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
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

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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