Solved

Passing a Null/Zero Form Value in Javascript

Posted on 2007-11-30
8
1,119 Views
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?
0
Comment
Question by:deltex141
  • 4
  • 2
8 Comments
 
LVL 29

Accepted Solution

by:
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);
0
 
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';
0
 
LVL 4

Author Comment

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

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

0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 4

Author Comment

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

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

Which is off because there is one there
0
 
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".
0
 
LVL 29

Expert Comment

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

Expert Comment

by:Computer101
ID: 20953170
Forced accept.

Computer101
Community Support Moderator
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

786 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