I put together the script below from solutions I found online. In the script, clicking on a link, inserts text into a textarea. But is it possible to add items from a form to the textarea the same way? You’ll see with the example below. The form is below the horizontal line. So clicking on a link will add selected items from that form to the textarea, on a single line. Any idea how it can be done?
Thanks
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Extended functionaly for textelements</title>
<script type="text/javascript">
function insertAtCaret(areaId,text) {
var txtarea = document.getElementById(areaId);
var scrollPos = txtarea.scrollTop;
var strPos = 0;
var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ?
"ff" : (document.selection ? "ie" : false ) );
if (br == "ie") {
txtarea.focus();
var range = document.selection.createRange();
range.moveStart ('character', -txtarea.value.length);
strPos = range.text.length;
}
else if (br == "ff") strPos = txtarea.selectionStart;
var front = (txtarea.value).substring(0,strPos);
var back = (txtarea.value).substring(strPos,txtarea.value.length);
txtarea.value=front+text+back;
strPos = strPos + text.length;
if (br == "ie") {
txtarea.focus();
var range = document.selection.createRange();
range.moveStart ('character', -txtarea.value.length);
range.moveStart ('character', strPos);
range.moveEnd ('character', 0);
range.select();
}
else if (br == "ff") {
txtarea.selectionStart = strPos;
txtarea.selectionEnd = strPos;
txtarea.focus();
}
txtarea.scrollTop = scrollPos;
}
</script>
</head>
<body>
<textarea id="textareaid" cols=50 rows =10></textarea>
<br>
<a href="#" onclick="insertAtCaret('textareaid','Java Beans ');return false;">Java Beans</a>
<br>
<a href="#" onclick="insertAtCaret('textareaid','Cocoa');return false;">Cocoa</a>
<hr>
<form>
Land <INPUT TYPE="radio" name= "mode" value="land"> Sea <INPUT TYPE="radio" name="mode" value="sea"> Air <INPUT TYPE="radio" name="mode" value="air">
<br>
Java<INPUT TYPE="checkbox" name = "item" value="Java Beans"> Cocoa <INPUT TYPE="checkbox" name="item=" value="Cocoa">
<br>
<a href="#" onclick="insertAtCaret('textareaid','Cocoa');return false;">Add to Text Box</a>
</form>
</body>
</html>