循环未考虑空的用户输入字段

时间:2019-07-05 10:14:14

标签: javascript html batch-file

我有一个批处理文件,其中包含一个HTML表单,用户具有1的3个输入字段。客户ID     2.名字     3.姓氏

如果我将“第一字段/客户ID”保留为空,则它将“第二字段/名字”值携带到“第一字段”插槽中。

这将使Customer ID变量值=成为“拳头名称”变量值,这将导致我的程序失败。

<!-- :
:: 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

IF "%CustomerID%"=="" (
    @echo
    echo.>"C:\Users\C28\Documents\RoboticProcessAutomation(RPA)\TestingStuff\%FirstName%%LastName%.csv"
    sqlcmd -S IX.COM -d GlblTransprncy -E -Q " EXEC dbo.GetSimilarCustIDs18 '%CustomerID%', '%FirstName%', '%LastName%' " -s "," -o "C:\Users\C283050\Documents\RoboticProcessAutomation(RPA)\TestingStuff\%FirstName%%LastName%.csv"
    pause
)  ELSE (
    @echo
    echo.>"C:\Users\C28\Documents\RoboticProcessAutomation(RPA)\TestingStuff\%CustomerID%.csv"
    echo Results for Customer ID will be returned shortly, Please check folder for the entered Customer ID results
    sqlcmd -S IX.COM -d GlblTransprncy -E -Q " EXEC dbo.GetSimilarCustIDs18 '%CustomerID%', '%@FirstName%', '%LastName%' " -s "," -o "C:\Users\C283050\Documents\RoboticProcessAutomation(RPA)\TestingStuff\%CustomerID%.csv"
)
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>

        <div style="display:flex; flex-direction: row; justify-content: center; align-items: center"> 
            <label for="Student">CustomerID:</label>
            <input type='text' name='CustomerID' size='25'></input><br>
        </div>

        <div style="display:flex; flex-direction: row; justify-content: center; align-items: center"> 
            <label for="Student">First Name:</label>
            <input type='text' name='FirstName' size='25'></input><br>
        </div>

        <div style="display:flex; flex-direction: row; justify-content: center; align-items: center"> 
            <label for="Student">Last Name:</label>
            <input type='text' name='LastName' size='25'></input><br>
        </div>
        <hr>
        <button onclick='pipeText()'>Submit</button>
    </body>
</html>

如果“客户ID /名字”输入字段保留为空,则循环应将此“客户ID”的变量值保留为空,而不是在行中输入下一个值,即“名字”值

1 个答案:

答案 0 :(得分:0)

您的For循环将其值定义为直到输出的第一个返回逗号为止的字符串,但是忽略前导定界符,因此,如果未输入任何内容,则将FirstName设置为{{1} }。如果没有输入任何输入,%%a将没有值。

我建议您将JavaScript代码更改为:

%CustomerID%

和您的close(Batch.WriteLine('"'+CustomerID+'","'+FirstName+'","'+LastName+'"')); 命令使用以下语法以保留任何空字符串位置:

Set

示例:

Set "CustomerID=%%~a"
Set "FirstName=%%~b"
Set "LastName=%%~c"