将HTML文本字段值携带到批处理文件变量中

时间:2019-07-04 13:28:33

标签: javascript html batch-file

我正在寻找一个HTML表单,该表单具有用于Customer.ID,名字和姓氏的三个输入框,这些输入框会将用户在这些框中输入的值作为变量携带到批处理文件中。然后,我正在寻找批处理值以回显单独输入的值。

<!-- :
:: textSubmitter.bat
@echo off
for /f "tokens=* delims=" %%a in ('mshta.exe "%~f0"') do (
    set "CustomerID=%%a"
    set "FirstName"=%%b"
    set "LastName"=%%c"
)

echo Your Customer ID is %CustomerID%
echo Your First Name is %FirstName%
echo Your Last Name is %LastName%
pause

-->

<html>
  <head>
    <title>COI Request</title>
  </head>
  <body>

    <script language='javascript' >
        function pipeText() {
            var CustomerID=document.getElementById('CustomerID').value;
            var Cust1= new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1);
            close(Cust1.Write(CustomerID));

            var FirstName=document.getElementById('FirstName').value;
            var Frst1= new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1);
            close(Frst1.Write(FirstName));

            var LastName=document.getElementById('LastName').value;
            var Lst1= new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1);            
            close(Lst1.Write(LastName));
      }
    </script>

    <input type='text' name='CustomerID' size='25'></input><br>
    <input type='text' name='FirstName' size='25'></input><br>
    <input type='text' name='LastName' size='25'></input><br>
    <hr>
    <button onclick='pipeText()'>Submit</button>
  </body>
</html>

希望将输入到HTML表单中的3个值作为变量值附加到批处理文件中,并显示在所附代码中。

1 个答案:

答案 0 :(得分:0)

您的代码有几个小错误。这有效:

<!-- :
:: textSubmitter.bat
@echo off
for /f "tokens=1-3 delims=," %%a in ('mshta.exe "%~f0"') do (
    set "CustomerID=%%a"
    set "FirstName=%%b"
    set "LastName=%%c"
)

echo Your Customer ID is %CustomerID%
echo Your First Name is %FirstName%
echo Your Last Name is %LastName%
pause
goto :EOF

-->

<html>
  <head>
    <title>COI Request</title>
  </head>
  <body>

    <script language='javascript' >
        function pipeText() {
            var CustomerID=document.getElementById('CustomerID').value;
            var FirstName=document.getElementById('FirstName').value;
            var LastName=document.getElementById('LastName').value;

            var Batch = new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1);
            close(Batch.WriteLine(CustomerID+','+FirstName+','+LastName));
      }
    </script>

    <input type='text' name='CustomerID' size='25'></input><br>
    <input type='text' name='FirstName' size='25'></input><br>
    <input type='text' name='LastName' size='25'></input><br>
    <hr>
    <button onclick='pipeText()'>Submit</button>
  </body>
</html>