|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Javascript for loop problem.
a page that im working on loads a table with information from a database using xajax. i have the number of items in the table and each item has a unique id but when i go to process the changes the user makes i get the error "document.getElementById("upc_" + i) has no properties". thought if i remove the for loop i get the first upc and no error. below is my javascript function.
function insert_upc() { var num = document.getElementById("num_rows").value; var i = 0; for(i=0;i<=num;i++) { var upc = document.getElementById("upc_" + i).value; document.getElementById("list").innerHTML = i; //xajax_import_upcs(id, upc); } } <tr bgcolor="#ededed"> <td rowspan="2"><input name="checkbox" value="checkbox" checked="checked" type="checkbox"></td> <td>SKU: B111 ---- Color: Midnight ---- Size: 34 X 30</td> <td rowspan="2">035481266126<input value="2056165" id="id_80" type="hidden"><input value="035481266126" id="upc_80" type="hidden"></td> </tr> |
|
#2
|
|||
|
|||
|
Are all of the numbers in the IDs sequential?
You could try this: Code:
function insert_upc()
{
var num = document.getElementById("num_rows").value;
var i = 0;
for(i=0;i<=num;i++)
{
if(document.getElementById("upc_" + i))
{
var upc = document.getElementById("upc_" + i).value;
document.getElementById("list").innerHTML = i;
//xajax_import_upcs(id, upc);
}
}
}
|
|
#3
|
|||
|
|||
|
i still see that it will not work
because Code:
var num = document.getElementById("num_rows").value;
the num is not parsed in integer do like this Code:
var num = parseInt(document.getElementById("num_rows").value);
|
|
#4
|
|||
|
|||
|
Specifying the second argument will keep the number from being treated as octal if the number ever has a leading zero.
Code:
var num = parseInt(document.getElementById("num_rows").value,10);
|
|
#5
|
|||
|
|||
|
problem solved
thanks alot for the help. the parseInt fixed the problem.
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Javascript for loop problem. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|