tags:

views:

62

answers:

2

hi

<script type="text/javascript" language="javascript">
function addElement() {
  var ni = document.getElementById('occupation').value;
  var numi = document.getElementById('theValue');
   numi.value = ni;
</script>

i use this code for add one text box values to another but this code work only for add one value not multiple value so plz tell me how can i add multiple values.

+1  A: 

Apply a class to all the textboxes you want to add together, and then get the elements by class rather than id. Iterate through the result set and add the values of each element.

stevebot
A: 

It's difficult to understand from your question which of these you are doing:

  1. You have a text box that has a value, and you want to set multiple text boxes to the same value as the first one.
  2. You have a single text box and you want to add the value of that field to another text box multiple times.

If you want 1

var ids = ['text_box_1', 'text_box_2', 'text_box_3'];
for(var i = 0; i < ids.length; i++) {
  document.getElementById(ids[i]).value = document.getElementById('occupation').value;
}

If you want 2

document.getElementById('target').value += document.getElementById('occupation').value;

You might even be asking for something else, honestly I don't know. What is your question?

Jesse Dhillon
i've two textboxes and there is multiple values in first textbox and other textbox is empty. when i select any value from first textbox and click on Add button than that value goes to another textbox. but i want to add multiple values. how can it possible
Are you talking about a `<select/>` or a `<input type="text"/>` or a `<textarea/>` when you say "text box"?
Jesse Dhillon
yes i m talking about <select/>