Parsing returned values from a multiple selection list in a form

  • Thread starter DigitalPrankster
  • Start date
D

DigitalPrankster

I have a form that I am using to generate an email with several user
selected fields being part of it. As part of this form, I have a select
box which allows the user to select which email addresses it should be
sent to. The box works great except that the CGI script I'm sending the
values to can only parse a single line for each field in the form. The
issue comes into play when someone selects more than one value in the
select box, the output of the select box seems to separate each value
on a separate line using a line feed (or carriage return, I can't
tell). The format that the CGI script needs is for a single line with
each of these values separated by a comma. I'm confident that a
javascript can do this fairly easily, but unfortunately, I am not very
well versed in javascript. I've found a few code snippets on the web
that I've mangled together, but since I don't really know what I'm
doing, it isn't working out so good. I've included what I have in the
form right now below (note that I've removed all of the other form data
but the select box code to save space). If anybody could point out what
I'm doing wrong, I would be most greatful!


<script language="JavaScript">
<!-- Start
function replaceChars(entry) {
out = "\n"; // replace this
add = ","; // with this
temp = "" + entry; // temporary holder

while (temp.indexOf(out)>-1) {
pos= temp.indexOf(out);
temp = "" + (temp.substring(0, pos) + add +
temp.substring((pos + out.length), temp.length));
}
document.form.list.value = temp;
--> End
</script>

<body>
<form name="form" method="post" action="/cgi-bin/soupermail.cgi"
onsubmit="replaceChars(document.form.list.value);return
document.form.list.value">
<select name="list" size="6" multiple id="select">
<option value="(e-mail address removed)">User 1</option>
<option value="(e-mail address removed)">User 2</option>
<option value="(e-mail address removed)">User 3</option>
<option value="(e-mail address removed)">User 4</option>
<option value="(e-mail address removed)">User 5</option>
<option value="(e-mail address removed)">User 6</option>
</select>
<input name="button_submit" type="submit" id="button_submit"
value="Send Email">
</form>
</body>
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top