Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9224765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:24:25+00:00 2026-06-18T04:24:25+00:00

How can I perform a simple validation on this HTA form to make sure

  • 0

How can I perform a simple validation on this HTA form to make sure that data is inputted and an option is selected? This should be simple, I’m not sure what I’m missing.

Any answers or suggestions would be appreciated.

Thanks.

<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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:24:26+00:00Added an answer on June 18, 2026 at 4:24 am

    I was stumped, so I rewrote this in vbscript.

    I have included bits of what I did to give you an idea of how to write to a text file, and validate your form with an HTA.

    The 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
    

    The 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>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine I have a class that represents a simple washing machine. It can perform
I want to perform some simple form validation in my controller. Here's an excerpt
Is there such a thing that finds numbers using regex and can perform simple
I have an issue, where by I am doing a simple form validation, that
can anyone suggest me a plugin/tool that can perform a code formatting at build
Let's assume that our system can perform actions, and that an action requires some
Let's say you have a business logic method that can perform some operation across
I've written a small console application that can perform certain tasks. The user interface
what I am trying to do is to set up functions that can perform
I have a form that validates using the jQuery plugin: Validation, v1.9.0. The validation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.