PDA

View Full Version : dynamically populate textarea from first webform



superbarbs
11-27-2006, 04:08 PM
I have 2 webforms, can one form with checkboxes populate a textarea on the second webform with the names of the checkboxes selected?

coothead
11-27-2006, 06:18 PM
Hi there superbarbs,

and a warm welcome to these forums. ;)

try it like this...

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script type="text/javascript">

window.onload=function() {
df=document.forms;
inp=df[0].getElementsByTagName('input');
for(c=0;c<inp.length;c++) {
if(inp[c].type=='checkbox') {
inp[c].onclick=function() {
if(this.checked==true){
df[1][0].value+=this.name+' ';
}
else {
df[1][0].value=df[1][0].value.replace(this.name+' ','');
}
}
}
}
}

</script>

</head>
<body>

<form action="#">
<div>
<input type="checkbox" name="foo"/>
<input type="checkbox" name="blah"/>
<input type="checkbox" name="dodah"/>
</div>
</form>

<form action="#">
<div>
<textarea cols="20" rows="3"></textarea>
</div>
</form>

</body>
</html>
coothead

terkini
11-28-2006, 08:28 AM
Hi CootHead,
This is a very interesting script. If I want to send the selected info in the text area to an email address, how do i add the "send" button to the script?

codeexploiter
11-28-2006, 09:41 AM
JavaScript can't send email (from Client-side). But you can use JavaScript(Client-side) and Server-side (ASP or PHP) to send information.

Check this article (http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=3480&lngWId=2)