• Post Reply Bookmark Topic Watch Topic
  • New Topic

Pre-check checkboxes via Post  RSS feed

 
Ben Schuster
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
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: 65833
    134
    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.
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!