Hello all.
Based on the image above, I have a table that gets its data from a MySql database, I would like to edit a field on that table within the table result. I am learning to use javascript so please be kind. On my table as you can see ID # 16 has an currentbal input field and a image button to click to call my function and pass the value of the ID to it. The ID corresponds to the record ID on my db so I know which record to edit.
Anyway, here is my js function:
function funcEdit(row_id){
var currentbal = document.getElementById('currentbal').value;
alert(currentbal);
}
It works perfectly for my first row but I am having a problem if I am calling the 2nd row, the currentbal value it still displays is my value on the 1st row. I know I need to change the ID of currentbal ID to make it unique. I was thinking of doing something like this:
<input name="currentbal(add the id here)" type="text" id="currentbal(add the id here)" class="input-mini" />
to make the currentbal ID unique so my currentbal ID will become currentbal16 or currentbal63 respectively. My problem is how to edit my js function, so that if row 1 is called
var currentbal = document.getElementById('currentbal').value;
becomes var currentbal = document.getElementById('currentbal16').value;
or var currentbal = document.getElementById('currentbal').value;
when row 2 is called. Basically I am having syntax issues I guess. Any guidance would be appreciated.
var currentbal = document.getElementById('currentbal' + row_id).value;
You simply have to add the numeric id to the end of your 'currentbal'
string to make a new string. Then search for that id.