By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,504 Members | 1,194 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,504 IT Pros & Developers. It's quick & easy.

Data from select box to formbox a.l.a Hotmail, yahoo etc

P: n/a
hey there

for my website, i am trying to create a messaging system and so far am
nearly finished, except for one thing. I am not sure how i can get
data from a select form box into a normal data box, and then seperate
them with a "," after every one.

_____________________ __________
To:|s*@hotmail.com,ooo@..|<---- |sh@hotma..|
|ooo@hotm..|
|qpr@hotm..|
|1121@hot..|
|__________|

lol if that diagram made ANY sense.

any help would be much appreciated, as i am pretty much tearing my
hair out now.

Many thanks,
Jack Bastow
(a55m0nk)
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
-[ CaMeL ]- a55m0nk wrote:
I am not sure how i can get
data from a select form box into a normal data box, and then seperate
them with a "," after every one.


Well, just iterate thorugh the options of your select box, buffer their
value and output the buffer into the text box. An example follows.
<form action="foo">
<select name="a">
<option value="Lu***@grandline.com">Luffy</option>
<option value="Zo***@grandline.com">Zorro</option>
<option value="Na**@grandline.com">Nami</option>
</select>

<input type="button"
value="&gt;&gt;"
onclick="transform(
this.form.elements['a'],
this.form.elements['b']);">

<input type="text" name="b">
</form>

<script type="text/javascript">
function transform(src, dest){
var a=[];
for(var ii=0; ii<src.options.length; ii++)
a[ii]=src.options[ii].value;
dest.value=a.join(",");
}
</script>
---
The following, while much more attractive, unfortunately doesn't work in
IE (but is fine in Mozilla).

Option.prototype.toString=function(){
return this.value;
}

function transform(src, dest){
dest.value=Array.prototype.join.call(src.options);
}
---
HTH
Yep.
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.