user358360
user358360

Reputation: 199

changing style with JS makes a hidden input field disappear?

im drawing a table with dates with a load of hidden fields

print   "<td";
{ $dm=date('Y-m-d',strtotime("+".$i." days", strtotime($m)));
print " class=\"overflow\"  id=\"$a::$dm\" onclick=\"function1(this)\" "
print " >";
print  "<input type='hidden' id=\""."hidden:$a::$dm"."\"    name=\"hiddenfield\" value='123' >";
}   
print " </td>";

then i want to click on the cell and add a value to the hidden element,and change the color of adjacent cells

but when the javascript changes style, the hidden element isnt accessible and the length of the array decrements by one each time

i can put the hidden input fields outside the table , but can i fix this ?

Javascript ........

>    days=5;
>     for (i=(c+1); i<(c+days);i++)
>     {
>     myTable.rows[r].cells[i].innerHTML = '';
>     j=myTable.rows[r].cells[i].id;//alert(i +" "+j) 
>     document.getElementById(j).style.borderRightStyle = "none";
>     document.getElementById(j).style.borderLeftStyle = "none";
>     document.getElementById(j).className = 'active'; 
>     ajj='hidden::'+j;alert(ajj);
>     //alert(document.getElementById(ajj).value)
>     alert(document.getElementsByName("hiddenfield").length);
>     }

i get a console message when i try to inspect that element alert(document.getElementById(ajj).value) is null

Upvotes: 0

Views: 79

Answers (1)

Kruga
Kruga

Reputation: 791

I think the problem is this line

myTable.rows[r].cells[i].innerHTML = '';

You are removing everything between your <td> tags, which includes the input field. Changing the style has nothing to do with it.

Upvotes: 1

Related Questions