views:

33

answers:

2

dear all.I want to use only one textfield for different results. what should I do if I want after pressing a few times a checkbox or another checkbox the results will appear sequentially in the textfield.for example:

<input type="checkbox" id="see" value="a">
<input type="checkbox" id="saw" value="b">

<input type="text" id="field">
<input type="button" id="show">

then i do something like:

 1. click "see"
 2. click "show"
 3. click "see"
 4. click "show"
 5. click "saw"
 6. click "show"
 7. click "saw"
 8. click "show"
 9. click "see"
 10. click "show"

then show results after click show button at text field:

aaba..and so on if any additional
+1  A: 

Try something like this:

$('input:checkbox').click(function() {
  $('#field').val($('#field').val() + $(this).val());
});​

Here's a working fiddle.

If you need a variant where you only record the clicks that create a checked state, just wrap the assignment in:

if( $(this).is(':checked') ) {...}
Ken Redler
+1  A: 
Garis Suero
Please review edited answer...
Garis Suero
yups..thanks a lot
klox