[英]Preserving form fields(input/select/checkbox) in an .hta file. So original user and/or another user can open and see the filled out information
I need some help with an .hta
file I am creating for my work. 我需要为自己的工作创建的
.hta
文件提供帮助。 I am good with HTML but JavaScript is another realm for me. 我对HTML很好,但是JavaScript对我来说是另一个领域。 I've always been able to look at examples and piece together different examples but what I'm trying to accomplish is beyond my expertise.
我一直能够查看示例并将不同的示例组合在一起,但是我要完成的工作超出了我的专业知识。
Right now I have successfully created an .hta
that allows a user to select a checkbox telling the code to select the school, then select an option in a drop-down and add any other information in a text field. 现在,我已经成功创建了一个
.hta
,允许用户选择一个复选框,告诉代码选择学校,然后在下拉列表中选择一个选项,并在文本字段中添加任何其他信息。 When the user clicks save changes, it outputs an .xml
file. 当用户单击“保存更改”时,它将输出一个
.xml
文件。
My issue is when a user closes the .hta
file, all of the fields and selections and check boxes are blank when re-opened. 我的问题是,当用户关闭
.hta
文件时,重新打开时所有字段,选择和复选框都为空白。 I have scoured code examples everywhere trying to find a way to preserve the data. 我遍地搜索代码示例,试图找到一种保存数据的方法。 I won't go into detail but html5 localstorage won't work and JavaScript cookies wont work because those are restricted to a local user.
我不会详细介绍,但是html5 localstorage无效,JavaScript cookie无效,因为它们仅限于本地用户。
I want to preserve all data that has been entered so any user(from any workstation) can open the .hta
and not have to refill out all the fields and selections. 我想保留已输入的所有数据,以便任何用户(从任何工作站)都可以打开
.hta
,而不必重新填写所有字段和选择。
The three solutions I have found: 我发现了三个解决方案:
An external serialized JSON file saved locally, then called when the .hta
is opened. 外部序列化的外部JSON文件保存在本地,然后在打开
.hta
时调用。
Using this guys JavaScript: hta-localstorage 使用这个家伙的JavaScript: hta-localstorage
Read the information from the created .xml
file. 从创建的
.xml
文件中读取信息。
Unfortunately, I lack the knowledge on how to implement any of those options. 不幸的是,我缺乏有关如何实现这些选项的知识。 If I give an example of my existing code, could someone help me implement one of the previous mentioned methods?
如果我举一个现有代码的例子,有人可以帮助我实现前面提到的方法之一吗? Or maybe someone has an easier alternative?
或者也许有人有一个更简单的选择?
Script: 脚本:
<script>
function WriteToFile()
{
try
{
var WshNetwork = new ActiveXObject("WScript.Network");
var userName = WshNetwork.UserName;
var fso, s;
fso = new ActiveXObject("Scripting.FileSystemObject");
s = fso.CreateTextFile("xml_output/sc_output.xml", true);
var B_B_P=document.getElementById("A_Bright_Beginning_Preschool").checked;
var B_B_P_selected=document.getElementById("A_Bright_Beginning_PreschoolSelected").value;
var B_B_P_other=document.getElementById("A_Bright_Beginning_PreschoolOther").value;
var A_S_Cath_S=document.getElementById("All_Saints_Catholic_School").checked;
var A_S_Cath_S_selected=document.getElementById("All_Saints_Catholic_SchoolSelected").value;
var A_S_Cath_S_other=document.getElementById("All_Saints_Catholic_SchoolOther").value;
s.writeline("\<\?xml version\=\"1\.0\" encoding\=\"UTF\-8\" standalone\=\"yes\"\?\>");
s.writeline("\<School\_data xmlns\:xsi\=\"http\:\/\/www\.w3\.org\/2001\/XMLSchema\-instance\"\>");
if (B_B_P==false)
{
s.writeline("");
}
else
{
s.writeline(" \<record\>");
s.writeline(" \<School\_Name\>A Bright Beginning Preschool\<\/School\_Name\>");
s.writeline(" \<School\_Seq\>001\<\/School\_Seq\>");
s.writeline(" \<Delay\>" + B_B_P_selected + "\<\/Delay\>");
s.writeline(" \<Other\>" + B_B_P_other + "\<\/Other\>");
s.writeline(" \<\/record\>");
}
if (A_S_Cath_S==false)
{
s.writeline("");
}
else
{
s.writeline(" \<record\>");
s.writeline(" \<School\_Name\>All Saints Catholic School\<\/School\_Name\>");
s.writeline(" \<School\_Seq\>002\<\/School\_Seq\>");
s.writeline(" \<Delay\>" + A_S_Cath_S_selected + "\<\/Delay\>");
s.writeline(" \<Other\>" + A_S_Cath_S_other + "\<\/Other\>");
s.writeline(" \<\/record\>");
}
s.writeline("\<\/School\_data\>");
s.Close();
}
catch(err)
{
var strErr = 'Error:';
strErr += '\nNumber:' + err.number;
strErr += '\nDescription:' + err.description;
document.write(strErr);
}
}
</script>
HTML: HTML:
<h1>School Closures</h1>
<br />
<form>
<table width="900" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" valign="middle"><input type="checkbox" name="A_Bright_Beginning_Preschool" id="A_Bright_Beginning_Preschool" /></td>
<td align="left" valign="middle">A Bright Beginning Preschool</td>
<td align="left" valign="middle"><select name="A_Bright_Beginning_PreschoolSelected" id="A_Bright_Beginning_PreschoolSelected">
<option value="" selected="selected"></option>
<option value="1 Hour Late">1 Hour Late</option>
<option value="2 Hours Late">2 Hours Late</option>
<option value="3 Hours Late">3 Hours Late</option>
<option value="4 Hours Late">4 Hours Late</option>
<option value="No School">No School</option>
</select></td>
<td align="left" valign="middle"><input name="A_Bright_Beginning_PreschoolOther" type="text" id="A_Bright_Beginning_PreschoolOther" size="80" /></td>
</tr>
<tr>
<td align="left" valign="middle"><input type="checkbox" name="All_Saints_Catholic_School" id="All_Saints_Catholic_School" /></td>
<td align="left" valign="middle">All Saints Catholic School</td>
<td align="left" valign="middle"><select name="All_Saints_Catholic_SchoolSelected" id="All_Saints_Catholic_SchoolSelected">
<option value="" selected="selected"></option>
<option value="1 Hour Late">1 Hour Late</option>
<option value="2 Hours Late">2 Hours Late</option>
<option value="3 Hours Late">3 Hours Late</option>
<option value="4 Hours Late">4 Hours Late</option>
<option value="No School">No School</option>
</select></td>
<td align="left" valign="middle"><input name="All_Saints_Catholic_SchoolOther" type="text" id="All_Saints_Catholic_SchoolOther" size="80" /></td>
</tr>
</table>
Are you creating the XML file every time in your WriteToFile code? 您是否每次都在WriteToFile代码中创建XML文件?
s = fso.CreateTextFile("xml_output/sc_output.xml", true); s = fso.CreateTextFile(“ xml_output / sc_output.xml”,true);
That'll overwrite the previously created XML file when called. 调用时,它将覆盖先前创建的XML文件。 You`ll need some logic in your code to check if the XML file exists, and if so, read the relevant content and populate your HTML fields with it.
您将需要代码中的一些逻辑来检查XML文件是否存在,如果存在,请阅读相关内容并用它填充HTML字段。
In pseudo(-ish)-code terms: 用伪代码表示:
if not fso.fileExists("output.xml") then
Set outFILE = fso.createTextFile("output.xml")
else
Set inFILE = fso.openTextFile("output.xml"), 1) ' ForReading
rawXML = inFILE.ReadAll
inFILE.Close
end if
.. there are some XML handling tools in vbscript (create an XML object and read it in, or process specific elements etc). .. vbscript中有一些XML处理工具(创建XML对象并读取它,或处理特定元素等)。 But you`ll need to sort the file creation issue first.
但是您需要首先对文件创建问题进行排序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.