複数のhtmlフォームを1つのvbscript関数に提出しようとしています。この関数の目的は、テキストファイルを更新することです。更新のために提出されたテキスト領域に応じて、関数が更新するテキストファイルを指定する必要があります。基本的には、すべてのテキスト領域のファイル更新を処理する関数が必要です。ここにコードスニペットがあります。複数のhtmlフォームをvbscript関数に送信
onload関数は、テキストファイルに現在あるテキストをテキスト領域に読み込みます。
F1およびF2機能は、テキスト領域をクリップボードにコピーします。基本的にはこれは単純なクイックリファレンスクリップボードです。
実際にどのようにこの概念をすべての機能に適用する必要があるかを見ることができます。複数のフォームがすべて単一の機能(読み取り、書き込み、コピー)に提出します。
<head>
<title>Quick Comments</title>
<HTA:APPLICATION
APPLICATIONNAME="Quick Comments"
SCROLL="YES"
>
</head>
<script language="VBScript">
sub Window_onLoad()
set oFSO=CreateObject("Scripting.FileSystemObject")
set oFile=oFSO.OpenTextFile("signature.txt",1)
text=oFile.ReadAll
document.all.var1.value=text
oFile.Close
set oFile=oFSO.OpenTextFile("initial.txt",1)
text=oFile.ReadAll
document.all.var2.value=text
oFile.Close
end sub
sub FileUpdate
Dim TheForm
Set TheForm = Document.field1
Set objFileToWrite = CreateObject("Scripting.FileSystemObject").OpenTextFile("signature.txt",2,true)
objFileToWrite.WriteLine(TheForm.signature.value)
objFileToWrite.Close
Set objFileToWrite = Nothing
end sub
sub F1
Dim TheForm
Set TheForm = Document.field1
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /c echo " & TheForm.signature.value & " | clip", 0, TRUE
end sub
sub F2
Dim TheForm
Set TheForm = Document.field2
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /c echo " & TheForm.initial.value & " | clip", 0, TRUE
end sub
</script>
<body>
<h1>Quick Comments</h1><hr>
<form id="field1" name="field1">
<textarea name="var1" id='signature' cols=75 rows=8></textarea>
<input type="button" name="copy" value="Copy" onclick="F1" language="vbscript">
<input type="button" name="update" value="Update" onclick="FileUpdate" language="vbscript">
</form>
<form id="field2" name="field2">
<textarea name="var2" id='initial' cols=75 rows=8></textarea>
<input type="button" name="copy" value="Copy" onclick="F2" language="vbscript">
<input type="button" name="copy" value="Copy" onclick="F1" language="vbscript">
</form>
</body>