/    Sign up×
Community /Pin to ProfileBookmark

Populate Code???

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=”http://www.w3.org/1999/xhtml” xml:lang=”en” lang=”en”>

<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>&nbsp;To:<input type=”checkbox” id=”cbto” value=”1″>

&nbsp;&nbsp;CC:<input type=”checkbox” id=”cbcc” value=”1″>

&nbsp;&nbsp;BCC: <input type=”checkbox” id=”cbcc” value=”1″>

&nbsp;&nbsp;<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>

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @scarickhoff spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...