Hello,
I"m trying to send mail to multi users, but i doesn"t succeded/
I doesn"t know how to add all the mails that i selected to the mailto tag.

this the the code that I wrote:

<SCRIPT LANGUAGE="JavaScript">
         function getSelected(opt) {
            var selected = new Array();
            var index = 0;
            for (var intLoop = 0; intLoop < opt.length; intLoop++) {
               if ((opt[intLoop].selected) ||
                   (opt[intLoop].checked)) {
                  index = selected.length;
                  selected[index] = new Object;
                  selected[index].value = opt[intLoop].value;
                  selected[index].index = intLoop;
               }
            }
            return selected;
         }

         function outputSelected(opt) {
            var sel = getSelected(opt);
            var strSel = "";
            for (var item in sel)       
               strSel += sel[item].value + "\n";
               
           }
      </SCRIPT> 

</head>
<body>
<jsp:include page="header.jsp"/>

<% String str=null; %>

<h1>The members</h1>
<table  width="100%" border="2" bordercolor="blue" class="tt">
		<tr>
		<td align="center" width="10%">select </td>
		<td align="center" width="25%">City</td>
		<td align="center" width="30%">Mail </td>
		<td align="center" width="20%">User Name </td>
		</tr>
</table>
<%  for (user u: projDB.getUser().values()){ %>
<form method="post"  >
<table  width="100%" border="2" bordercolor="blue" class="tt">
		<tr>
		<td align="center" width="10%"><input type="checkbox" name="mail" value=<%= u.getMail()%>></td>
		<td align="center" width="25%"> <%= u.getCity()%></td>	
		<td align="center" width="30%"> <%= u.getMail()%></td>	
		<td align="center" width="20%"> <%= u.getUserName()%></td>	
		</tr>
		</table>
		<%str+=u.getMail()+",";%>	
<br><br>
<%} %>
<input type="button" value="send" onclick="outputSelected(this.form.mail)" >
</form>

please help me how can i solve this.

thank u

Try this:

function outputSelected(f) {
  var inputs = f.getElementsByTagName('input');
  var sel = [];
  for (var i=0; i<inputs.length; i++) {
    if(inputs[i].name !== 'mail') { continue; }
	if (inputs[i].checked) { sel.push(inputs[i].value); }
  }
  emailStr = sel.join(";");
  subject = "TEST";
  body_message = "This is a test message";
  var mailto_link = 'mailto:' + sel.join(";") + '?subject=' + subject + '&body=' + body_message;
  win = window.open(mailto_link,'emailWindow');
  if (win && win.open &&!win.closed) win.close();
}

Call with:

<input type="button" value="send" onclick="outputSelected(this.form);" >

I'm not sure how reliable this is cross-broswer and cross-computer, but it works on this hack machine (Win2000) in IE6, FF 3.6.13, Opera 10.63. Email client was my system default, OE, in all cases (Opera asked, FF and IE just did it).

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.