Solved

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

Posted on 2010-11-08
5
551 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Google Tag Manager - Add Trigger Using Div class 22 99
Debugging Html 8 43
What are MicroServices? 4 67
wordpress theme 8 39
Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
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
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

734 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