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

  • Thread starter -[ CaMeL ]- a55m0nk
  • Start date
C

-[ CaMeL ]- a55m0nk

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:|[email protected],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)
 
Y

Yann-Erwan Perio

-[ CaMeL ]- a55m0nk said:
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="(e-mail address removed)">Luffy</option>
<option value="(e-mail address removed)">Zorro</option>
<option value="(e-mail address removed)">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);
}
 

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
474,438
Messages
2,571,699
Members
48,796
Latest member
Greg L.
Top