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 6932309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:41:23+00:00 2026-05-27T11:41:23+00:00

How do I disable the submit button until the user has chosen a file?

  • 0

How do I disable the submit button until the user has chosen a file?

I have a form on my page:

<table>
    <form method="post" enctype="multipart/form-data" id="messageupload">
    <@spring.bind "messageUploadCommand.*"/>
        <tr>
            <td><@spring.formInput 'messageUploadCommand.multipartFile' '' 'file' /></td>
            <td><button type="submit" id="searchButton">Upload</button></td>
            <td><@spring.formSingleSelect 
                    'messageUploadCommand.messageFormat', 
                    messageFormats, '' /> 
                <@spring.showErrors  '<br>', 'error' /> </td>
        </tr>
    </form>
</table>

If the user submits the form before choosing a file I get

freemarker.template.TemplateException: Error executing macro: formSingleSelect required parameter: options is not specified. 
 at freemarker.core.Macro$Context.sanityCheck(Macro.java:211) 
 at freemarker.core.Macro$Context.runMacro(Macro.java:169) 
 at freemarker.core.Environment.visit(Environment.java:603) 
 at freemarker.core.UnifiedCall.accept(UnifiedCall.java:106) 
 at freemarker.core.Environment.visit(Environment.java:210) 
 at freemarker.core.MixedContent.accept(MixedContent.java:92) 
 at freemarker.core.Environment.visit(Environment.java:210)
 at freemarker.core.Environment.process(Environment.java:190)
 at freemarker.template.Template.process(Template.java:237)
 at ...
  • 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-05-27T11:41:23+00:00Added an answer on May 27, 2026 at 11:41 am

    This is how I did it:

    <table>
        <form method="post" enctype="multipart/form-data" id="messageupload">
        <@spring.bind "messageUploadCommand.*"/>
            <tr>
                <#assign onChangeScript = "document.getElementById('uploadButton').disabled = (value.length=0); ">
                <td><@spring.formInput 'messageUploadCommand.multipartFile' 'onchange=\"${onChangeScript}\"' 'file' /></td>
                <td><button type="submit" disabled="true"
                              id="searchButton">Upload</button></td>
    
                <td><@spring.formSingleSelect 
                        'messageUploadCommand.messageFormat', 
                        messageFormats, '' /> 
                    <@spring.showErrors  '<br>', 'error' /> </td>
            </tr>
        </form>
    </table>
    

    I added the file-chooser onchange script via a Freemarker variable, and disabled the button by default. The onchange script tests for the length of the value, i.e. the filename, being zero.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a contact form that has a disabled submit button until all
I have a form, and want to disable/enable its submit button depending on whether
I want to disable the submit button when a user submits the form so
I have a form like so: <form action= method=post id=form name=form enctype=multipart/form-data> <input name=action
I want to disable my submit button until all the fields have values.. how
I have a form for uploading images. I'd like to disable the submit button,
I have a form with a submit button. I want to disable the submit
I currently have my code set to disable the submit button when the field
The following code is being used to disable a Submit button once it has
Details: Only disable after user clicks the submit button, but before the posting back

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.