Passing JScript value to VbScript

Eduardo Aviles
Eduardo Aviles used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Sam JacobsCitrix Technology Professional / Director of TechDev Services, IPM

Commented:
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.

Author

Commented:
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 JacobsCitrix Technology Professional / Director of TechDev Services, IPM

Commented:
Hi Eduardo ... Do you need to go back to VBScript?
You can't do what you need staying in JavaScript?

Author

Commented:
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]);
                  }
                  }

Author

Commented:
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");
                  
                  d.innerHTML += "<br /><span>Document Number: <input type='text'style='width:150px;'value='' /></span> <span>Rev: <input type='text' style='width:150px'  value='' /> </span>";
      
            }
            

      
            function myfunction(item, index) {
                  
                  d.innerHTML = d.innerHTML + "index[" + index + "]: " + item + "<br>";
            }
            

      </script>
Sam JacobsCitrix Technology Professional / Director of TechDev Services, IPM

Commented:
Sorry, Eduardo... just saw this.
I'll be in front of my PC in an hour or so, and I'll check it out.
Sam JacobsCitrix Technology Professional / Director of TechDev Services, IPM

Commented:
Hi Eduardo,

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

Author

Commented:
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.

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title></title>

      <link rel="stylesheet" type="text/css" href="/css/normalize.css">

      <link rel="stylesheet" type="text/css" href="/css/result-light.css">

  <style type="text/css">
    div { padding:5px;}
  </style>
 
 
      <script type="text/javascript">
        
            var d;
            function add_fields() {
                  d = document.getElementById("content");
                  
                  d.innerHTML += "<br /><span>Document Number: <input type='text'style='width:150px;'value='' /></span> <span>Rev: <input type='text' style='width:150px'  value='' /> </span>";
      
            }
            

      
            function myfunction(item, index) {
                  
                  d.innerHTML = d.innerHTML + "index[" + index + "]: " + item + "<br>";
            }
            

      </script>
      
<script language="VBScript">
      Option Explicit

      Sub ProcessInfo_OnClick
      
      
       End Sub
      
      Sub Message
      
            Msgbox docNum
      
      
       End Sub
</script>

</head>




<body>
 
         <div>
                  <div id="content">
                        <span>Document Number: <input type="text" style="width:150px;" name="docNum[]" value=""/>
                        <span>Rev: <input type="text" style="rev:20px;" name="rev[]" value="" />   <input type="button" id="more_fields" onclick="add_fields();" value="+" />
                  </div>
         </div>

 
 
  <tr>
      <td>
            <input type="button" value="Submit" onclick="myfunction()">
      </td>
  </tr>
 
 
</body>
</html>
Sam JacobsCitrix Technology Professional / Director of TechDev Services, IPM

Commented:
Eduardo,

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.

Sam

Author

Commented:
Thank you Sam, I really appreciate the help.
Citrix Technology Professional / Director of TechDev Services, IPM
Commented:
Hi Eduardo,

An .hta will only work in IE, so I took the liberty of converting it to pure JavaScript.
Check out the attached to see if it does what you are looking for.

Sam
Eduardo.html

Author

Commented:
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 JacobsCitrix Technology Professional / Director of TechDev Services, IPM

Commented:
Hmmm. Strange. I just uploaded the file that I was using. Let me double-check it.
Sam JacobsCitrix Technology Professional / Director of TechDev Services, IPM

Commented:
Hi Eduardo,

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

Author

Commented:
I did a copy and saved it on the application, let me try it again

Author

Commented:
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.


Thank you again.

Author

Commented:
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.
Sam JacobsCitrix Technology Professional / Director of TechDev Services, IPM

Commented:
Hi Eduardo,

You are most welcome.

Sam

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial