I am creating a web-mail application. I want to include an address book feature. The addresses will be listed in a drop-down menu (address_book). Next to the drop-down menu are three buttons To (toFill), CC (ccFill), BCC(bccFill)
Once the user selects and address from the drop-down menu, the user can click on one of three buttons, and the script will populate the appropriate text field (to, cc, bcc) using the onclick command.
I need to keep in mind separating the addresses with a ;. Also, if there already is an address in the text field, I do not want to overwrite it, just add to it.
I have some code using checkboxes, but it is not so strong and keeps giving me errors. Below is the code I would like to modify (or rewrite), but I know nothing about javascript…
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=”
<head>
<meta http-equiv=”content-type” content=”text/html; charset=iso-8859-1″ />
<title>Populate</title>
<style type=”text/css” media=”screen”>
body {
font-family: verdana, arial;
font-size: .7em;
line-height: 24px;
}
</style>
<script type=”text/javascript”>
var i, cbto, cbcc, cbbc, fields = new Array (“to”,”cc”,”bc”);
function getEmail() {
var email = document.getElementById(‘list’).value;
for (i = 0; i < 3; i++) {
var fieldval = document.getElementById(fields[i]).value;
var chkd = eval(“document.getElementById(‘cb”+fields[i]+”‘).checked”);
if (chkd) {
if (!fieldval) {
document.getElementById(fields[i]).value = email;
} else {
document.getElementById(fields[i]).value = fieldval + “; “+email;
}
}
}
}
</script>
</head>
<body>
<form action=”someprogram.cgi”>
<select id=”list”>
<option value=””>Select one…</option>
<option value=”[email protected]”>[email protected]</option>
<option value=”[email protected]”>[email protected]</option>
</select> To:<input type=”checkbox” id=”cbto” value=”1″>
CC:<input type=”checkbox” id=”cbcc” value=”1″>
BCC: <input type=”checkbox” id=”cbcc” value=”1″>
<input type=”button” value=”Add” onclick=”getEmail()”>
To: <input type=”text” id=”to” size=”60″ /><br />
CC: <input type=”text” id=”cc” size=”60″ /><br />
BC: <input type=”text” id=”bc” size=”60″ /><br />
<br />
<input type=”submit” />
</form>
</body>
</html>