View Full Version : Resolved Is it possible to assign values to document.getElementsByName('field')

12-29-2010, 04:00 PM
I have to update the rowid(assigned to checkbox) whenever the textbox value is updated and this needs updating value of document.getElementsByName('rf_select[]') when checkbox value matches the textbox id. There can be mutliple number of rows each with a uniqueID (checkbox value) that matches with the textboxID onload.

Code :-

<td align="center"><input type='checkbox' name='rf_select[]' id='rf_select' value="rowId" CHECKED border="none"/>
<td align="left"><input type='text' name='policy_no' id="rowId" size='25' value="test" onBlur=handleRowId('policy_no'); /></td>

<script language="javascript">
function handleRowId(){
var arr = new Array();
var rowarr = new Array();
arr = document.getElementsByName('policy_no');
rowarr = document.getElementsByName('rf_select[]');
for(var i = 0; i < arr.length; i++)
var obj = arr.item(i); //alert(obj.id + " = " + obj.value);
for(var j=0; j< rowarr.length; j++){
if(rowarr[j].value == obj.id){
document.getElementsByName('rf_select')[j].value = rowarr[j].value+"#@#"+obj.value;

I am having problem assigning values here - document.getElementsByName('rf_select')[j].value = rowarr[j].value+"#@#"+obj.value;

Any help is appreciated.

Old Pedant
12-30-2010, 04:00 AM
You do NOT have any fields on that page named "rf_select".

That may be the name in PHP, but in the browser their name really and truly *IS* "rf_select[]".

The browser's DOM doesn't treat the "[]" in the name special the way PHP does.