Link to home
Start Free TrialLog in
Avatar of deltex141
deltex141

asked on

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

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?
ASKER CERTIFIED SOLUTION
Avatar of Joe Wu
Joe Wu
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of deltex141
deltex141

ASKER

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
It'll be replaced with an escaped slash  It should work perfectly.
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.
That worked great, Thanks!