473,385 Members | 1,372 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

getting combo values

how to get the selected combo values in a text box using on change event
Aug 1 '07 #1
3 1581
gits
5,390 Expert Mod 4TB
hi ...

moved from js-articles-section to forum ...

please be a little bit more specific with your question ... you want the selected values of a multiselect select-box? ... and/or post some code you have done already ...

kind regards
Aug 1 '07 #2
hi gits,
here is my code

[HTML]<html>
<head>
<script type="text/javascript">
function moveNumbers()
{
var no=document.getElementById("no")
var option=no.options[no.selectedIndex].text
var txt=document.getElementById("result").value
txt=txt + option
document.getElementById("result").value=txt
}
</script>
</head>

<body>
<form>
Select numbers:<br />
<select id="no" onchange="moveNumbers()" multiple="3">
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
</select>
<input type="text" id="result" size="20">
</form>
</body>[/HTML]



for the above code if suppose i select three values i need to get that values in that text box with comma separated with onchange event
Aug 2 '07 #3
gits
5,390 Expert Mod 4TB
hi ...

use the following function, and have a look how it works. selectedIndex only returns the first index of the selected option, so we have to loop and ask for the selected options:

Expand|Select|Wrap|Line Numbers
  1. function moveNumbers() {
  2.     var no_node         = document.getElementById("no");
  3.     var no_node_options = no_node.childNodes;
  4.     var result_node     = document.getElementById("result");
  5.     var result_text     = '';
  6.  
  7.     for (var i = 0; i < no_node_options.length; i++) {
  8.         var opt = no_node_options[i];
  9.  
  10.         if (opt.selected) {
  11.             result_text += opt.text + ', ';
  12.         }
  13.     }
  14.  
  15.     // remove last comma through matching an regEx
  16.     result_text = result_text.replace(/(, )$/, '');
  17.  
  18.     result_node.value = result_text;
  19. }
  20.  
and some additional hints ;)

- use code-tags when posting code here in the forum
- always use a semicolon to terminate every line of code in js

kind regards
Aug 2 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Giulio | last post by:
Hello, I have a continuous form with a combo box inside. From the combo box I can pick some values which, by the "after-update" event, change some other combo box values determined by a query....
9
by: deko | last post by:
What is it with these dates? What are they so much trouble? All I want to do is subtract an hour, but not if that makes dtmTest less than dtmClt. Dim dtmStart As Date Dim dtmEnd As Date Dim...
15
by: sara | last post by:
Hi I'm pretty new to Access here (using Access 2000), and appreciate the help and instruction. I gave myself 2.5 hours to research online and help and try to get this one, and I am not getting...
2
by: jim | last post by:
I have created a Table that has 13 fields and 2 Primary Keys, e.g. 60 1, 60 2, ... 60 28, 61 1, 61 2, ... 61 28, etc... I want to create a Form where I can input the Primary Key values to query...
1
by: Arun | last post by:
Hi Group, I was trying to link a combo box with a list control and having some trouble with that. Could anyone please help me with that. Here's the example of the scenario. Combo Box ;-...
4
Rabbit
by: Rabbit | last post by:
Cascading Combo/List Boxes This tutorial is to guide you in the creation of Cascading combo/list boxes. That is when you have multiple combo/list boxes where the selection of an option in one...
1
by: madsy6 | last post by:
Hi, I have a combo box with some values and 3 links. I am taking a combination of selected value of combo box and the link selected and redirecting to a certain page. I am using a querstring to...
1
by: tremonti92 | last post by:
Hello.. I have a table with a field name called 'Professions'. There are many same multiple values for this field, for example, there are many records with the value 'Doctor' under this field. ...
32
by: tfurubay | last post by:
Hi, I am setting up a database and would like a combo box on a form to store two values. for example, there's a ID and a Description. I can easily get the combo box to show both the ID and the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.