Solved

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

Posted on 2010-11-08
5
544 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
Comment Utility
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
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn how to count occurrences of each item in an array.

763 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