Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Passing a Null/Zero Form Value in Javascript

Posted on 2007-11-30
Last Modified: 2009-07-29
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?
Question by:deltex141
  • 4
  • 2
LVL 29

Accepted Solution

Göran Andersson earned 500 total points
ID: 20381728
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);
LVL 29

Expert Comment

by:Göran Andersson
ID: 20381744
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';

Author Comment

ID: 20382756
Is the syntax on this correct? I'm getting en error

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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


Author Comment

ID: 20383553
Specifically, it saying that it "Expected ;" on the

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

Which is off because there is one there
LVL 29

Expert Comment

by:Göran Andersson
ID: 20383661
Sorry, a typo that I happened to repeat by copying/pasting...

"it" should of course be "if".
LVL 29

Expert Comment

by:Göran Andersson
ID: 20548672
Checking back to see if you had any progress?

Expert Comment

ID: 20953170
Forced accept.

Community Support Moderator

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Utilizing an array to gracefully append to a list of EmailAddresses
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question