I have built an HTA application with JScript language and VbScript. I am trying to pass the value of JScript variable to VbScript, but I am stuck. Can you please help. Here is the JScript code: (I need to pass the docNum [ ] and rev [ ] values, as there may be multiples.)
<script type="text/javascript">
var room = 1;
function add_fields() {
room++;
var objTo = document.getElementById('room_fileds')
var divtest = document.createElement("div");
divtest.innerHTML = '<div class="content"><span>Document Number: <input type="text" style="width:150px;" name="docNum[]" value="" /></span><span>Rev: <input type="text" style="rev:20px;" name="rev[]" value="" /></div>';
objTo.appendChild(divtest)
}
</script>
<script language="VBScript">
Option Explicit
Sub ProcessInfo_OnClick
End Sub
</script>
Thank you
JScriptVB Script
Last Comment
Sam Jacobs
8/22/2022 - Mon
Sam Jacobs
I haven't created any HTA apps, but what I do for my ASP.Net apps is to have JavaScript call the file again, passing the values in the QueryString (e.g. http://FQDN/filename.ext?docnum=xxxx&rev=yyyy). Then, have the VBScript code retrieve the values from the QS.
Eduardo Aviles
ASKER
Thank you Sam, I had attempted something similar by putting all the strings in an input delimited by ',' but the users did not want that. They wanted dynamically to have the UI add a new input row by the means of a plus sign. That's what I have done which the user can add as many rows as they want on the UI, now I need to pass the collection so that I can parse it. Since the users may have multiple documents to process.
Sam Jacobs
Hi Eduardo ... Do you need to go back to VBScript?
You can't do what you need staying in JavaScript?
Hello Sam, 99% of the code is already built in VbScript and am up against a deadline and I am not an expert in Javascript. If I can just get how to display the docNum[] values that I can loop thru them then I can figure out the rest. I tried this with no success:
function myfunction() {
var myStringArray = [docNum];
var arrayLength = myStringArray.length;
for (var i = 0; i < arrayLength; i++) {
alert(myStringArray[i]);
}
}
Eduardo Aviles
ASKER
I changed the code around to getElementById("content") and now I get an error of index[undefined]: undefined
<script type="text/javascript">
var d;
function add_fields() {
d = document.getElementById("content");
First, the reason that you can't pass values from JavaScript to VBScript is that VBScript code is parsed before JavaScript, so that once JavaScript is being executed, there's no going back to evaluate VBScript.
While I haven't written any HTA applications, I have never seen brackets in an HTML input field (name="docNum[]").
If docNum is an array, where is it getting its values from?
Sam
Eduardo Aviles
ASKER
Its getting the values from an input from the user.. Here is the full code complete. Sorry about that. The UI allows the user to select the plus sign and add another row to enter more input.
Thanks for the source ... it helps a lot.
I stand corrected ... in an .hta, it appears that you CAN execute JavaScript from VBScript.
I'm going to look at this some more for a bit and get back to you shortly.
Good Morning Sam,
Thank you so much for the code. I have tried it and I am getting an error when selecting the + sign "Object doesn't support property or method 'getElementsByClassName" on this line: var docs = document.getElementsByClassName("doc");
Sam Jacobs
Hmmm. Strange. I just uploaded the file that I was using. Let me double-check it.
I just downloaded the file from the link above, and it seems to work fine.
Did you copy and paste it the contents from your screen or download the file (Save Link As...)?
Sam
Eduardo Aviles
ASKER
I did a copy and saved it on the application, let me try it again
Eduardo Aviles
ASKER
Hello Sam,
I retried it and it exactly what I need. Since it is HTML there are some differences to HTA as that's why it was failing before, but I can figure it out. Thank you so much for your help, as the code is working perfectly.
Hello Sam, Thank you again for the code it works as expected. The code is well written and am able to use this in multiple applications. I really appreciated your time and knowledge. Thank you again.