0

I need to populate 2 different text boxes when something is selected in the dropdown box.

From the fiddle, i can be do it with one.

Sorry, let me clarify a little more. This dropdown list actually is the person's LONG NAME. I'm trying to populate a "nickname" and "contact number" textbox when his name is selected.

Look at this demo which I now have 2 textbox in there. In my database, I have a record of everyone's Fullname, nickname, and contact number. It's up to me how I create a select list, but I only want to select his full name to show the nickname and contact number on 2 seperate boxes..

Emerson F
  • 805
  • 3
  • 9
  • 17

4 Answers4

1

Sorry but your example has only one texarea...

However if I don't' have misunderstood your question you can simply do that:

var mytextbox = document.getElementById('mytext');
var mytextbox2 = document.getElementById('mytext2');

var mydropdown = document.getElementById('dropdown');

mydropdown.onchange = function(){

   mytextbox.value = mytextbox.value  + this.value;
   mytextbox2.value = mytextbox2.value  + this.value;
}
xdevel2000
  • 20,780
  • 41
  • 129
  • 196
1
<textarea id="mytext"></textarea>
<textarea id="mytext2"></textarea>
<select id="dropdown">
<option value="">None</option>
<option value="contactnumber1">text1</option>
<option value="contactnumber2">text2</option>
<option value="contactnumber3">text3</option>
<option value="contactnumber4">text4</option>
</select>

var mytextbox = document.getElementById('mytext');
var mytextbox2 = document.getElementById('mytext2');
var mydropdown = document.getElementById('dropdown');

mydropdown.onchange = function () {
mytextbox.value = mydropdown.options[this.selectedIndex].text;
mytextbox2.value = mydropdown.options[this.selectedIndex].value;
};
quickLearner
  • 141
  • 2
  • 12
0

do you mean, you want to append selection each time some body selects item from drop down? I do not see two text boxes in your fiddle that is why I am asking...

if you want unique values selected then..

var mytextbox = document.getElementById('mytext');
var mydropdown = document.getElementById('dropdown');
var strValue =  new String();
mydropdown.onchange = function(){
if(strValue.indexOf(this.value)<=0){
   if(strValue!="")
{
    strValue += "," + this.value;
}
else
{
    strValue = this.value
}
}
mytextbox.value = strValue;
}
quickLearner
  • 141
  • 2
  • 12
  • Sorry, let me clarify a little more. This dropdown list actually is the person's LONG NAME. I'm trying to populate a "nickname" and "contact number" textbox when his name is selected. – Emerson F Jan 30 '13 at 16:12
  • where are the contact number's coming from (for each long name)? – quickLearner Jan 30 '13 at 16:15
0

So you are wanting two values to be populated by one tag. With that said, what if you just put data attributes in the option tag? data-contactNumber data-longName

<select>  
<option value="x" data-contactNumber = "yyyy" data-longName="zzzz">  
.....
</select>  

Then you can just assign the selected option text boxes the individual data attrs??