Cześć,
Mam problem z banalną funcją w JS do zmiany stylu wyświetlania obiektu:
kawałek strony:
<table width="620" border="1"> <td width="50" class="et_heads">ID
</td> <td class="et_heads" width="160">PRODUCENT
</td> <td class="et_heads" width="250">MODEL
</td> <td class="et_heads" width="100" style="text-align:center">STAN
<span style="font-size:10px"> (dostępne/wszystkie)
</span></td> <td width="100" class="et_heads">REZERWUJ
</td> {section name=id loop=$ile start=0 step=1}
<td onClick="showMore(magazyny_{$smarty.section.id.index+1})">{$smarty.section.id.index+1}
</td> <td onClick="showMore(magazyny_{$smarty.section.id.index+1})">{$magazyn[id]['producent']}
</td> <td onClick="showMore(magazyny_{$smarty.section.id.index+1})">{$magazyn[id]['model']}
</td> <td style="text-align:center">{$magazyn[id]['dostepne']} / {$magazyn[id]['wszystkie']}
</td> <td style="text-align:center">{if $magazyn[id]['stan']}
<a href="index.php?page=stan&action=rezerwuj&what={$maszyna[id]['id']}">rezerwuj
</a>{else}rezerwuj{/if}
</td> <tr id="magazyny_{$smarty.section.id.index+1}" style="display:none"> <td colspan="5" style="background-color:#ACEAF4"> <table width="624" class="magTabMore"> <td colspan="2">Dostępne {$magazyn[id]['dostepne']} z {$magazyn[id]['wszystkie']}
<br /><br /></td> <td align="left">Magazyny:
</td> <td align="left"> Rezerwacje:
</td> <td align="left" valign="top"> {foreach from=$magazyn[id]['stany'] item=v}
{if $v['ilosc'] != '0'}
<li>{$v['nazwa']}: {$v['ilosc']} szt.
</li>{/if}
{/foreach}
<td align="left" valign="top"> <ul> {foreach from=$magazyn[id]['rezerwacje'] item=v}
<li>{$v['login']} - do {$v['data_koniec_rezerwacji']}
</li> {/foreach}
{/section}
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.
<td onClick="showMoremagazyny_{$smarty.section.id.index+1})">{$magazyn[id]['model']}
</td>
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 nullGdy dam w scripts.js
window.onload =function showMore(what){ to konsola wypluwa:
Uncaught ReferenceError: showMore is not defined