quicky... form & pop up...

M

Mel

i have an text field and a button

when user click on button it popups up list of emails in a form

user selects a bunch of people from the form (check boxes) and when the
window is closed the selection should be placed in the text field separated
by ";" semicolon

can someone help ?
 
L

Lee

Mel said:
i have an text field and a button

when user click on button it popups up list of emails in a form

user selects a bunch of people from the form (check boxes) and when the
window is closed the selection should be placed in the text field separated
by ";" semicolon

can someone help ?

<html>
<head>
<title>demo</title>
<script type="text/javascript">
var addressBook=[ "Me", "You", "Him", "Her", "Them" ];
function popup() {
globalHTML="<html><body><form>";
for(var i=0;i<addressBook.length;i++) {
globalHTML+="<input type=\"checkbox\" name=\"c\" value=\""
+addressBook+"\">&nbsp;"+addressBook+"<br>\n";
}
globalHTML+="<center><input type=\"button\" value=\"Done\" onclick=\""
+"opener.importAddr(this.form);self.close()\"></center>"
+"</form></body></html>";
window.open("javascript:eek:pener.globalHTML",
"popup","width=400,height=400,resizable");
}
function importAddr(f) {
for(var i=0;i<f.c.length;i++) {
if(f.c.checked) {
document.forms[0].toAddr.value+=f.c.value+";";
}
}
}
</script>
</head>
<body>
<form>
<input type="button" value="To:" onclick="popup()">
<input name="toAddr">
</form>
</body>
</html>
 
R

RobG

Lee said:
Mel said: [...]
can someone help ?

Lee's solution is OK, here's an improvement (to me anyway). The
addresses are only added if there aren't already in the text box.

The HTML is constructed as an array, then written to the window which
may be faster as the list of addresses gets longer.

Creates the window as a local variable.

Gets rid of "javascript" in:

window.open("javascript:eek:pener.globalHTML",

Script only, HTML unchanged ... have fun!


<script type="text/javascript">

var addressBook=[ "Me", "You", "Him", "Her", "Them" ];

function popup() {
var newWin = window.open('','popup','width=400,height=400,resizable');
var globalHTML = ['<html><body><form>'];
for (var i=0; i<addressBook.length; i++) {
globalHTML.push(
'<input type="checkbox" name="c" value="'
+ addressBook
+ '">&nbsp;'
+ addressBook
+ '<br>'
);
}
globalHTML.push(
'<center><input type="button" value="Done"'
+ 'onclick="opener.importAddr(this.form);'
+ 'self.close()"></center>'
+ '</form></body></html>'
);

newWin.document.write(globalHTML.join(''));
newWin.document.close();
}
function importAddr(f) {
var ele = document.forms[0].toAddr;
var addStr = ele.value;
for(var i=0; i<f.c.length; i++) {
if(f.c.checked && addStr.indexOf(f.c.value) < 0) {
ele.value += f.c.value + ";";
}
}
}
</script>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top