This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Pre-check checkboxes via Post  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a pretty simple request, but I'm new to Javascript so thanks upfront for your patience.

I'm trying to pre-populate some check boxes based on values passed to a JSP page through either a POST or GET call.

So if my post string is:
http://www.example.com/form.jsp?animal=dog&color=blue

It would pre-check the "dog" and "blue" answer values my form.jsp page:


Obviously, my real-world application is more complicated than this; but I can figure it out based on the answer to this example.
 
Author and ninkuma
Marshal
Posts: 66799
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A few things:
  • You mention JavaScript, but I see no further mention of JavaScript or the need for it. Are you confusing JSP with JavaScript?
  • On a POST, there will be no parameters on the URL -- that's how a GET does it. A POST wil have the params in the request body.

  • That said, both the JSP (as well as servlets) can obtain the params the same way regardless of whether they come in on a GET or a POST.

    To accomplish your goal, you'd use a conditional expression to add the checked attribute to the checkboxes that you want checked. I'll post a small code example in a few minutes.
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Posts: 66799
    168
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator


    Rinse, lather, repeat as needed.

    P.S. I assume that this is an academic exercise? Because in the "real world" you'd never POST to a JSP, but to its page controller servlet.
     
    Ben Schuster
    Greenhorn
    Posts: 2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks Bear Bibeault, that bit of code is working.


    Much appreciated.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!