Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

populate a textbox from combobox value?

Status
Not open for further replies.

lminmei

Programmer
Feb 1, 2000
111
0
0
US
I have a combobox named "cboNumber" that i want a user to select a value from...
and when they select a value, that value is inserted into a textbox named "txtNumber"...
so when they select multiple values (a, b, c) from the combobox...
i want to be able to concatenate each consecutive value selected in the combobox and have it show up in the textbox as:

1st selection (a) from combobox => textbox value = 'a'
2nd selection (b) from combobox => textbox value = 'a, b'
3rd selection (c) from combobox => textbox value = 'a, b, c'
...

can someone help me out with this problem?
thanks
Derek
 
Code:
function checkCombo(){
  theSelect = document.getElementById("myCombo")
  txt = ""
  for (x=0; x<theSelect.options.length; x++){
    if (theSelect.options[x].selected){
      txt+= theSelect.options[x].value + ","
    }
  }
  if (txt.length > 0) txt = txt.substr(0,txt.length-1)
}

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
thanks for the reply...
i'll try this out!

Derek
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top