954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Pass parameters between Javascript and ASP




chan karan
Newbie Poster
13 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

Please use the forum's CODE tags when posting.

JavaScript runs on the client. ASP runs on the server. You cannot "pass" variables between them, per se.

The only time ASP runs is when a REQUEST is sent to the web server, either a GET or a POST.

The way you send values to an ASP form is by adding a QueryString to your GET Requests, or by populating form values for your POST Requests (or, "form submits").

tgreer
Made Her Cry
Team Colleague
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
 

Sorry for asking the wrong question.
Base on the above code, i can call the vb.exe program. Can i pass the parameters from javascript to vb.exe program???

chan karan
Newbie Poster
13 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

I see. Well, you're passing in a value to the function, correct? Is that value you want to "pass" to the activeX object? I see you're executing the method with "commandParms", but you're never setting "commandParms" equal to anything. Should it contain the value you pass to the JavaScript function?

Okay, I'm going to assume that you want commandParms = "123".

<SCRIPT type="text/javascript" LANGUAGE="JavaScript">
<!--
function startWord(x)
  {
commandParms = document.getElementById(x).value;
   var oShell = new ActiveXObject("Shell.Application");
    var commandtoRun="C:\\Karan\\Automation.exe";
oShell.ShellExecute(commandtoRun, commandParms, "", "open", "1");
  }
  //-->
</script>
</head>
<body>
<form>
<input type="text" name="par_1" value="123">
<input type="button" value="Click me!" onclick="startWord('par_1')">
</form>
</body>
</html>
tgreer
Made Her Cry
Team Colleague
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
 

The error came out after added the "commandParms = document.getElementById(x).value;"
is the server not read this sentence??

chan karan
Newbie Poster
13 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

No, the server wouldn't process that... it's JavaScript, which would run on the client.

Change name="par_1" in the input text element to id="par_1" .

tgreer
Made Her Cry
Team Colleague
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
 

Thank you for your help.

I use the alert sentence to check the value on getelelment, but the value is "NULL".

do it mean the value can't pass to the function???

chan karan
Newbie Poster
13 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

I assure you this works. I have no idea what "getelement" means, sorry.

Here's the most simplified test version I can make for you:

<html>
<head>
<script type="text/javascript">
function startWord(x)
{
  var commandParms = document.getElementById(x).value;
  alert(commandParms);
}
</script>
</head>
<body>
<form>
<input id="txt" type="text" value="123" />
<input id="btn" type="button" value="Click" onclick="startWord('txt')" />
</form>
</body>
</html>
tgreer
Made Her Cry
Team Colleague
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
 

Thx a lot , i success la, thank you very much~~

if i want to pass two parameters, am i need to add one more text for another parameter??

chan karan
Newbie Poster
13 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

That's completely up to you. You have enough now to learn the mechanism and finish it on your own.

tgreer
Made Her Cry
Team Colleague
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
 

Thank you for your helping.

As spoken, i want to pass two parameters to vb.exe. I tried to use the array for my passing parameters, but it don't work. I have no idea on that. Would you please to help me and give me some comment??

[html]function startWord(x,y)
{
dim theStr(1)
var oShell = new ActiveXObject("Shell.Application");
var commandtoRun="C:\\Karan\\Email.exe";
var theStr(0) = document.getElementById(x).value;
var theStr(1) = document.getElementById(y).value;
oShell.ShellExecute(commandtoRun, theStr(), "", "open", "1");
}[/html]

chan karan
Newbie Poster
13 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You