This week's book giveaway is in the Python forum.
We're giving away four copies of Python Continuous Integration and Delivery and have Moritz Lenz on-line!
See this thread for details.
Win a copy of Python Continuous Integration and Delivery this week in the Python 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

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.
 
Marshal
Posts: 67239
170
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
    Marshal
    Posts: 67239
    170
    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.
     
    She still doesn't approve of my superhero lifestyle. Or this shameless plug:
    Become a Java guru with IntelliJ IDEA
    https://www.jetbrains.com/idea/
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!