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 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 user to be able to communicate with other users
I just want to enable or disable the button inside a ControlTemplate for a
Using a configuration file I want to enable myself to turn on and off
I'm working on an ASP.NET website which targets desktop browsers. We want to enable
I want to loop over the contents of a text file and do a
I have a form, and want to disable/enable its submit button depending on whether
I'm using Jörn Zaefferers autocomplete plugin for jQuery to enable a live search field,
I am trying to get the first input field in a form that isn't
function safe(){ if($(this).is(':checked')){ $(select[name='sort']).attr(disabled, disabled); $(input[name='group']).attr(disabled, disabled) } else { $(select[name='sort']).attr(disabled, false); $(input[name='group']).attr(disabled, false)
I'd like to have a group of HTML text <input> 's that can be

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.