Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pre-check checkboxes via Post

Status
Not open for further replies.

upplepop

IS-IT--Management
Jun 1, 2002
173
US
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:

Code:
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.
 
This forum is intended for JSP server-side questions, for pure Javascript, you should use this [link
]one[/url]

Anyway, the checked attribute should do the trick.

Code:
My favorite animal is:<br />
<input type="checkbox" name="animal" value="dog" [COLOR=red]checked[/color]/>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" [COLOR=red]checked[/color] />Blue<br />
<input type="checkbox" name="color" value="red" />Red<br />
<input type="checkbox" name="color" value="green" />Green<br />

Cheers,
Dian
 
Thanks Diancecht,

I used the checked attribute, but had to modify the code a bit.

Here's what ended up working:
Code:
<input type="checkbox" name="animal" value="dog" ${param.animal == 'dog' ? 'checked' : ''}/>Dog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top