Mam problem z banalną funcją w JS do zmiany stylu wyświetlania obiektu:
kawałek strony:
<table width="620" border="1"> <tr> </tr> {section name=id loop=$ile start=0 step=1} <tr> </tr> <tr id="magazyny_{$smarty.section.id.index+1}" style="display:none"> <td colspan="5" style="background-color:#ACEAF4"> <table width="624" class="magTabMore"> <tr> </tr> <tr> </tr> <tr> <td align="left" valign="top"> <ul> {foreach from=$magazyn[id]['stany'] item=v} {/foreach} </ul> </td> {foreach from=$magazyn[id]['rezerwacje'] item=v} {/foreach} </tr> </table> </td> </tr> {/section} </table> </div>
scripts.js, ładowany w sekcji head.
// JavaScript Document function showMore(what){ //alert ('f str'); if (document.getElementById(what).style.display=='none'){ //alert ('try block'); document.getElementById(what).style.display='block'; } else{ //alert ('try none'); document.getElementById(what).style.display='none'; } }
Generalnie w tabeli w wierszu 1 chcę zmienić styl wyświetlania wiersza 2 w zdarzeniu onclick z użyciem funkcji js.
zmienia
<tr id="magazyny_{$smarty.section.id.index+1}" style="display:none">
{$smarty.section.id.index+1} przyjmuje wartość 1,2,3...
Błąd w konsoli to: Uncaught TypeError: Cannot read property 'style' of null
Gdy dam w scripts.js window.onload =function showMore(what){ to konsola wypluwa: Uncaught ReferenceError: showMore is not defined