Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Passing a variable from a client-side Javascript Input box to .cmd file on server

Posted on 2010-11-08
5
Medium Priority
?
564 Views
Last Modified: 2012-05-10
Hello experts.  I have a simple test web page I want to develop.  On the page, I have an input box and a button, which when clicked is supposed to execute a .cmd file on the web server and use the inputted value in the input box as part of the parameters requested.  

This is the javascript on my webpage that I found when searching for how to do this:

<SCRIPT LANGUAGE="JavaScript">
function testResults (form) {
    var TestVar = form.inputbox.value;
    alert ("You typed: " + TestVar);
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="myform" ACTION="" METHOD="GET">Enter something in the box: <BR>
<INPUT TYPE="text" NAME="inputbox" VALUE=""><P>
<INPUT TYPE="button" NAME="button" Value="Click" onClick="testResults(this.form)">
</FORM>

The function "testresults" is called when I click the button.  What I want to do instead of seeing an alert window (the sample provided) is to do something like call ASP code like this that I've used before:

<% dim oShell
Dim lRet
Set oShell = Server.CreateObject("Wscript.shell")
LRet=oShell.Run("C:\Test.cmd")
%>

The additional step I'd want to code is to run the "Test.cmd" and pass to it the value from the Input Box into the script that makes up the Test.cmd file.  This is the script when you edit the .cmd file:

"C:\Program Files\Testexecutable.exe" PassedValue=%TestVar%

So, my questions are a) how to properly write code to take the value placed in the Input Box to this script in my .cmd file and run the server side executable and b) is there a more efficient way to do this?  
0
Comment
Question by:FPLNET
  • 3
  • 2
5 Comments
 
LVL 7

Expert Comment

by:dxdinh
ID: 34086008
Can you try this

Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "cmd /K C:\Program Files\Testexecutable.exe " _ TestVar

Or
Return = oShell.Run("C:\Program Files\Testexecutable.exe"  & TestVar, 1, true)

More on this
http://msdn.microsoft.com/en-us/library/d5fk67ky(VS.85).aspx
0
 

Author Comment

by:FPLNET
ID: 34086102
Thanks for the quick response--how would I code the 'onclick' part of the javascript and call the ASP code?  Is it created as a function or something? I suppose I should have made that a question as well...
0
 
LVL 7

Accepted Solution

by:
dxdinh earned 2000 total points
ID: 34086490
with classic ASP you would have to create page and using javascript to redirect the page with the parameter in the querystring

function Something_OnClick ()
{
 var p1 = "TestVar";
  self.document.location = "MyPage.asp?param1=" + p1;
}

 if you using JQuery you can leverage a lot of using AJAX call and make your page load faster.
 
0
 

Author Comment

by:FPLNET
ID: 34087623
I am fine with using Ajax if that's easier--at this point I've tried a number of things but no dice--I think the biggest problem I'm having is getting the right syntax down so the Javascript "onclick" event passes the value entered into the Input Value field to the command in the .cmd file I showed above.  I tried the code above but I was getting error messages (so I suspect something else along the way was wrong)...I'm fine tearing down what I have and starting from scratch if necessary.
0
 
LVL 7

Expert Comment

by:dxdinh
ID: 34088393
Is it possible if you can post some of your snippet and error message that you have ... so I can have some ideas of what you are facing.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

972 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