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

  • Home
  • SEARCH
  • 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 4339046
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:09:50+00:00 2026-05-21T11:09:50+00:00

I want to enable the input field when check box is checked. Also, I

  • 0

I want to enable the input field when check box is checked. Also, I want to make a server side validation of the text field, to be filled, if the check box is selected, the problem I face is that when I make check for more than one and submit the form with empty values of the filed then make validation in the servlet and return the result to the user to fill the inputs, one of the check fields is checked and the other is not, even I use param for filed stability for both, I don’t know what is the reason!

Here’s the HTML code

 <div class="groupElement">

  <input type="checkbox" name="communicationWay" id="communicationWay2" value="emailOption" ${param.communicationWay == 'emailOption'?'checked':'' } onchange="chgtx('email','communicationWay2')"/>
  <label>Email</label>


     <input class="inpClass" id="email" type="text" name="emailComm" value="${param.emailComm}" disabled/>

</div>

 <div class="groupElement">

  <input type ="checkbox" name="communicationWay" id="communicationWay"  value="cellPhoneOption" ${param.communicationWay == 'cellPhoneOption'?'checked':''} onchange="chgtx('cellPhone','communicationWay')" />
   <label> Cell phone number</label>

    <input class="inpClass" id="cellPhone" type ="text" name="cellPhoneNoComm" value="${param.cellPhoneNoComm}" disabled />

     </div>

and here’s the java script function that trigger between enabling and disabling the input fields

 function chgtx(field, checkbox) {

            var myField = document.getElementById(field);
            var checkBtton = document.getElementById(checkbox);
            myField.disabled= !checkBtton.checked;

        }
  • 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-21T11:09:51+00:00Added an answer on May 21, 2026 at 11:09 am

    Your checkbox elements have the same name. So in the server side you have to use request.getParameterValues() to get all checked values.

    String[] communicationWays = request.getParameterValues("communicationWay");
    // ...
    

    When you use request.getParameter(), such as ${param} is doing, only one value will be returned, which is the first one of the group. You can use ${paramValues} to get all values in EL.

    However, using ${paramValues} in EL to set the checked state isn’t exactly trivial. There are two ways to solve this:

    1. Create a custom EL function which does something like

      ${util:contains(paramValues.communicationWays, 'emailOption') ? 'checked' : ''}
      ${util:contains(paramValues.communicationWays, 'phoneOption') ? 'checked' : ''}
      

      with a

      public static boolean contains(Object[] array, Object value) {
          Arrays.sort(array);
          return Arrays.binarySearch(array, value) > -1;
      }
      
    2. Create a Map<String, Boolean> in servlet and use it instead in EL.

      Map<String, Boolean> communicationWays = new HashMap<String, Boolean>();
      request.setAttribute("communicationWays", communicationWays);
      
      for (String communicationWay : request.getParameterValues("communicationWay")) {
          communicationWays.put(communicationWay, true);
      }
      

      with

      ${communicationWays.emailOption ? 'checked' : ''}
      ${communicationWays.phoneOption ? 'checked' : ''}
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to enable an 'other text' field when the 'option other' radio button
I have a input field. When the onchange event is triggered, I want to
I've a simple html form with text field with id=zip what I want to
I want my validation control to be enable/disable with javascript. When I click on
I have an HTML input field that I want the user to be able
I want to enable auto update script in flex3. i am using below code
I want to enable the users of my website to download the files from
I want to enable the user to select a video file from the on-device
I want to enable only two columns in the DataGridview to be able to
I want to enable GZIP compression on my gSOAP client. How can I do

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.