Solved

Problems pulling in Javascript Form Variables containing a ForwardSlash (/)

Posted on 2007-11-15
5
762 Views
Last Modified: 2013-11-19
I have a Javascript function that pulls in a couple of variables from a form, it works fine until it tries to pull in a variable that contains a forwardslash ( / ), then it just cuts off the field at the slash.

The function looks like this:

function runJob() {

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

So, for the Serial value, it will pull in a field of 12345 just fine, but a field of 12345/6789 will cut off at the /

For clarification here is the variable as declared in the table

<td align="right">~{sSerialNumber}:</td>
<td align="left"><input type="text" name="Serial" size="12" maxlength="30" onfocus="this.scrollIntoView(false)"/></td>

Any ideas?
0
Comment
Question by:deltex141
  • 2
  • 2
5 Comments
 
LVL 21

Accepted Solution

by:
nizsmo earned 500 total points
Comment Utility
Try modify your function to this and see if it works.
function runJob() {

  var serialValue = frmTable.Serial.value;

  serialValue = serialValue.replace("/","\/");

  var shell = new ActiveXObject("WScript.shell");

  shell.run("S:/function.bat "+frmTable.Item.value+" "+serialValue);

}

Open in new window

0
 
LVL 4

Author Comment

by:deltex141
Comment Utility
function runJob() {
  var serialValue = frmTable.Serial.value;
  serialValue = serialValue.replace("/","\/");
  var shell = new ActiveXObject("WScript.shell");
  shell.run("S:/function.bat "+frmTable.Item.value+" "+serialValue);
}

What is the / going to be replaced with? We still need the slash to be pulled in, not just replaced or removed
0
 
LVL 3

Expert Comment

by:kylealanhale
Comment Utility
It'll be replaced with an escaped slash  It should work perfectly.
0
 
LVL 21

Expert Comment

by:nizsmo
Comment Utility
yes as kylealanhale said, it will escape the "/" as it is conflicting with your code. Don't worry, the / won't get deleted or removed.

hope this helps.
0
 
LVL 4

Author Closing Comment

by:deltex141
Comment Utility
That worked great, Thanks!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now