Tuesday, May 21, 2024
 Popular · Latest · Hot · Upcoming
145
rated 0 times [  148] [ 3]  / answers: 1 / hits: 69093  / 13 Years ago, sun, september 25, 2011, 12:00:00

I have a variable account_number in which account number is stored. now i want to get the value of the element having id as account_number. How to do it in javascript ?



I tried doing document.getElementById(account_number).value, but it is null.



html looks like this :



<input class='transparent' disabled type='text' name='113114234567_name' id='113114234567_name' value = 'Neeloy' style='border:0px;height:25px;font-size:16px;line-height:25px;' />


and the js is :



function getElement()
{
var acc_list = document.forms.editBeneficiary.elements.bene_account_number_edit;

for(var i=0;i<acc_list.length;i++)
{
if(acc_list[i].checked == true)
{

var account_number = acc_list[i].value.toString();
var ben_name = account_number + _name;

alert(document.getElementById(' + ben_name.toString() + ').value);
}
}


}



here bene_account_number_edit are the radio buttons.



Thanks


More From » html

 Answers
32

Are you storing just an integer as the element's id attribute? If so, browsers tend to behave in strange ways when looking for an element by an integer id. Try passing account_number.toString(), instead.



If that doesn't work, prepend something like account_ to the beginning of your elements' id attributes and then call document.getElementById('account_' + account_number).value.


[#89935] Friday, September 23, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
averyc

Total Points: 102
Total Questions: 113
Total Answers: 89

Location: Taiwan
Member since Mon, Sep 6, 2021
3 Years ago
;