I have a form. Let’s called it myform.
Inside there are checkboxes, such as these two:
<input type='checkbox' name='power_convention[]' value='SOME VALUE #1' />
<input type='checkbox' name='power_evidence[]' value='SOME VALUE #2' />
At the end of the form, there’s a textarea.
<textarea id="elm1" name="comments" rows="15" cols="80" style="width: 80%">
If power_convention is checked, I want it to immediately append the value of that checkbox into the comments checkbox with the following structure:
<h3>SOME VALUE #1</h3><br />
Similarly, if power_evidence is clicked, I want it to do the same thing, but obviously after whatever came before it.
How would I go about doing this?
Thanks!
A jQuery solution:
DEMO
This only works if
valdoes not contain any special regular expressions characters. In this case you would have to escape them.Update: Actually, you don’t need a regular expression here,
v.replace(val, '')will be just fine (thanks @Pinkie);An alternative to regular expressions would be to recreate the content of the textarea:
DEMO 2