View Full Version : Pre-check checkboxes via Post

09-08-2011, 03:48 PM
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:

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

My favorite animal is:<br />
<input type="checkbox" name="animal" value="dog" />Dog<br />
<input type="checkbox" name="animal" value="cat" />Cat<br />
<input type="checkbox" name="animal" value="horse" />Horse<br />

My favorite color is:<br />
<input type="checkbox" name="color" value="blue" />Blue<br />
<input type="checkbox" name="color" value="red" />Red<br />
<input type="checkbox" name="color" value="green" />Green<br />

Obviously, my real-world application is more complicated than this; but I can figure it out based on the answer to this example.