Übergeben Sie die Variable vom Stapel an den HTML-Eingabewert

Übergeben Sie die Variable vom Stapel an den HTML-Eingabewert

Ich muss eine Variable aus einer Batchdatei an einen HTML-Eingabewert übergeben. Wenn ich %variable%den HTML-Eingabewert einstelle, wird dieser zurückgegeben %variable%, aber nicht der tatsächliche Wert.

Mein Code:

<!-- :
 :: textSubmitter.bat
 @echo off

 set "location=bob"



 for /f "tokens=1-8 delims=," %%a in ('mshta.exe "%~f0"') do (
     set "dossier=%%a"
     set "occupation=%%b"
     set "lieu=%%c"
    set "dated=%%d"
     set "datef=%%e"
     set "ets=%%f"
    set "type=%%g"
     set "subdi=%%h"
 )

     echo "Dossier =%dossier%"
     echo "Occupation =%occupation%"
     echo "Lieu :=%lieu%"
    echo "Date Debut : =%dated%"
     echo "Date Fin : =%datef%"
     echo "Entreprise : =%ets%"
    echo "Type : =%type%"
     echo "Subdi : =%subdi%"

 pause
 goto :EOF

 -->

 <html>
   <head>
     <title>Classement chantier</title>
   </head>
   <body>

     <script language='javascript' >
         function pipeText() {
             var dossier=document.getElementById('dossier').value;
             var occupation=document.getElementById('occupation').value;
             var lieu=document.getElementById('lieu').value;
            var dated=document.getElementById('dated').value;
             var datef=document.getElementById('datef').value;
             var ets=document.getElementById('ets').value;
            var type=document.getElementById('type').value;
             var subdi=document.getElementById('subdi').value;

             var Batch = new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1);
             close(Batch.WriteLine(dossier+','+occupation+','+lieu+','+dated+','+datef+','+ets+','+type+','+subdi));
       }
     </script>

     Dossier : <input type='text' name='dossier' size='25' value='%location%'></input><br>
     Occupation : <input type='text' name='occupation' size='25'></input><br>
     Lieu : <input type='text' name='lieu' size='25'></input><br>
    Date Debut : <input type='text' name='dated' size='25'></input><br>
     Date Fin : <input type='text' name='datef' size='25'></input><br>
     Entreprise : <input type='text' name='ets' size='25'></input><br>
    Type : <input type='text' name='type' size='25'></input><br>
     Subdi : <input type='text' name='subdi' size='25'></input><br>

     <hr>
     <button onclick='pipeText()'>Submit</button>
   </body>
 </html>

Im HTML-Formular %location%sollte die Variable den Wert „bob“ zurückgeben, sie gibt jedoch „ %location%“ zurück.

<input type='text' name='dossier' size='25' value='%location%'>

Wie stelle ich die Batchvariable auf den HTML-Eingabewert ein, um den Wert „Bob“ zu erhalten?

Antwort1

Kombiniert man die Antworten aus mehreren ähnlichen Fragen, könnte eine Lösung wie folgt aussehen:

  1. Fügen Sie Ihrem Element ein idAttribut (z. B. ) hinzu .locationinput

  2. Lesen Sie den Wert %location%mit ActiveX/Wscript und ersetzen Sie dann den Standardwert mithilfe von JavaScript inputüber das Ereignis window.onload1 .

Ihr Code könnte im Wesentlichen also etwa so aussehen:

<script language='javascript'>
    window.onload = function(e){
        var envlocation = new ActiveXObject('wscript.shell');
        envLocation = envlocation.ExpandEnvironmentStrings('%location%');
        document.getElementById('location').value = envLocation
    }
</script>

Dossier : <input type='text' id='location' name='dossier' size='25'></input><br>

1 document.onloadschien hier leider nicht zu funktionieren.


Antwort2

Vielen Dank, ich habe es so hinbekommen, aber ich muss den Javascript-Code unten anpassen:

<script language='javascript'> 
     window.onload = function(e){
     var envlocation = new ActiveXObject('wscript.shell');
     envLocation = envlocation.ExpandEnvironmentStrings('%dossier%');
     document.getElementById('dossier').value = envLocation     
     envLocation = envlocation.ExpandEnvironmentStrings('%occupation%');
     document.getElementById('occupation').value = envLocation  
     envLocation = envlocation.ExpandEnvironmentStrings('%lieu%');
     document.getElementById('lieu').value = envLocation    
     envLocation = envlocation.ExpandEnvironmentStrings('%dated%');
     document.getElementById('dated').value = envLocation   
     envLocation = envlocation.ExpandEnvironmentStrings('%datef%');
     document.getElementById('datef').value = envLocation   
     envLocation = envlocation.ExpandEnvironmentStrings('%ets%');
     document.getElementById('ets').value = envLocation     
     envLocation = envlocation.ExpandEnvironmentStrings('%type%');
     document.getElementById('type').value = envLocation    
     envLocation = envlocation.ExpandEnvironmentStrings('%subdi%');
     document.getElementById('subdi').value = envLocation } 
</script>

Jede Hilfe wird geschätzt ...

verwandte Informationen