0

この HTA フォームで簡単な検証を実行して、データが入力され、オプションが選択されていることを確認するにはどうすればよいですか? これは単純なはずです。何が欠けているのかわかりません。

回答や提案をいただければ幸いです。

ありがとう。

<html><head><title>Write data to text file</title>

<HTA:APPLICATION 
border="thin" 
borderStyle="normal" 
caption="yes" 
maximizeButton="no" 
minimizeButton="yes" 
showInTaskbar="yes" 
innerBorder="yes"
navigable="yes"
scroll="auto"
scrollFlat="yes" />


<script language="javascript">
window.resizeTo(480,150)


function Writedata()
{
var fso = new ActiveXObject("Scripting.FileSystemObject");


var write_id;
write_id = document.getElementById('write_id').value ;

alert('The data has been written to \n' + write_id);
var s = fso.OpenTextFile(write_id, 8, true);

s.WriteLine(document.getElementById('name_id').value);


s.Close();
}

</script>


</head>
<body>

<table>
<tr>
<h3>Input some information</h3>
<form>
<td>Input: </td><td><input type="text" name="name" value="" id="name_id"></td>

<td><select id="write_id">
  <option name="write" value="">Select an Option</option>
  <option name="write" value="C:\temp\option1.txt">Option1</option>
  <option name="write" value="C:\temp\option2.txt">Option2</option>
</select></td>

<td><input type="button" onclick="Writedata()" value="submit"></td>
</form>
</tr>
</table>


</body>
</html>
4

1 に答える 1

0

困惑したので、これを vbscript で書き直しました。

テキスト ファイルに書き込む方法と、HTA を使用してフォームを検証する方法のアイデアを提供するために、私が行ったことの一部を含めました。

vbscript:

Set wshShell = CreateObject( "WScript.Shell" )
strSender = wshShell.ExpandEnvironmentStrings( "%USERNAME%" ) ' Get the current Username


Dim Checkmark

Sub Validate

If form.Flag.checked = True Then ' Find out if your Checkbox is checked
    Checkmark = "*"
Else
    Checkmark = ""
End IF

If form.field1.value = "" Then                    ' Validate the form
    alert "Please enter an number!", "0", "Title"
ElseIf IsNumeric(form.field1.value) = False Then
    alert "Please enter a valid number!", "0", "Title"
ElseIf form.drop_down1.Value = "" Then
    alert "Please select a save location!", "0", "Title"
ElseIf form.field1.value < 100000 Then
    alert "Please enter a six digit number!", "0", "Title"
ElseIf form.field1.value > 999999 Then
    alert "Please enter a six digit number!", "0", "Title"
Else
    SaveData
End If

End Sub


Sub SaveData                    ' Write data to a text file
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(form.drop_down1.Value) Then
Set objFile = objFSO.OpenTextFile(form.drop_down1.Value, 8)
    strLine = form.field1.value & vbtab & Checkmark & vbtab & strSender  & vbtab & Now ' fields that will be written
    objFile.WriteLine strLine
    MsgBox "The Information was successfully written to the file.", "0", "Title"
    objFile.Close
Else
Set objFile = objFSO.CreateTextFile(form.drop_down1.Value) ' If file does not exist, create file
    strLine = form.field1.value & vbtab & Checkmark & vbtab & strSender  & vbtab & Now
    objFile.WriteLine strLine
    MsgBox "The Information was successfully written to the file.", "0", "Title"
    objFile.Close
End If
End Sub

HTML:

<form name="form">
<h2>Imput</h2>
<tr><td><lable>Data: </lable></td><td><input type="text" name="field1" size="25"></td>    </tr>
<tr><td><lable>Save Location: </lable></td><td><select name="drop_down1">
<option type="text" name="select" value="">Select an option</option>
<option type="text" value="SavePath1...">SavePath1</option>
<option type="text" value="SavePath2...">SavePath2</option>
<option type="text" value="SavePath3...">SavePath3</option>
</select></td><td><input type="checkbox" name="Flag" value="">Flag *</td></tr>
</table>
<input type="button" value="Submit" onClick="Validate">
<input type='reset' id='ResetFields' value='Clear Fields' />
</form>
于 2013-02-01T12:52:42.567 に答える