Passing JScript value to VbScript

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
Eduardo AvilesAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sam JacobsDirector of Technology Development, IPMCommented:
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 AvilesAuthor 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 JacobsDirector of Technology Development, IPMCommented:
Hi Eduardo ... Do you need to go back to VBScript?
You can't do what you need staying in JavaScript?
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Eduardo AvilesAuthor 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]);
                  }
                  }
Eduardo AvilesAuthor 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 JacobsDirector of Technology Development, IPMCommented:
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 JacobsDirector of Technology Development, IPMCommented:
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
Eduardo AvilesAuthor 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 JacobsDirector of Technology Development, IPMCommented:
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
Eduardo AvilesAuthor Commented:
Thank you Sam, I really appreciate the help.
Sam JacobsDirector of Technology Development, IPMCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Eduardo AvilesAuthor 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 JacobsDirector of Technology Development, IPMCommented:
Hmmm. Strange. I just uploaded the file that I was using. Let me double-check it.
Sam JacobsDirector of Technology Development, IPMCommented:
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
Eduardo AvilesAuthor Commented:
I did a copy and saved it on the application, let me try it again
Eduardo AvilesAuthor 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.
Eduardo AvilesAuthor 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 JacobsDirector of Technology Development, IPMCommented:
Hi Eduardo,

You are most welcome.

Sam
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JScript

From novice to tech pro — start learning today.