hello

how do i populate or change the values in multiple textfields using javascript? the textfields has the same ID because it is in a repeat region. i manage to change just the top most textfield using javascript. so how to populate the rest?

<script type="text/javascript">	
function chalb()
  {
  document.getElementById('albid').value = document.getElementById('alb').value;	
  }
</script>
.
.
.
<input name"albid" id="albid" type="text" value="<?php echo $row_rspri_schimages['alb_id']); ?>">

'albid' refers to the textfield ID i want to change and 'alb' is the ID of a select menu.


lets say there are 10 repeated textfields, a user selects a value from the select menu 'alb' and a button when click will execute the "chalb()" function. the function suppose to change all the textfields values to the new selected value but it only changes the top textfield.

help? is it an array that i'm missing?

Recommended Answers

All 3 Replies

Hey you can take the array of inputs and check wether it is 'text' type or not. If yes then change their values. here is the code

<script type="text/javascript">	
function chalb()
{
  var textFields = document.getElementsByTagName('input');
  var i=0;
  for(;i<textFields.length; i++) 
  {
     if(textFields[i].type='text') {
        textFields[i].value = document.getElementById('alb').value;
     }

  }

 	
}
</script

thanks a lot chap! got it done nicely..at first it didnt work with "getElementsByTagName" because i have a number of input buttons also, then i change it to "getElementsByName" and it works flawlessly.

bless ye mate! 3 cheers for you!

please mark this thread as solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.