/    Sign up×
Community /Pin to ProfileBookmark

Echo’d table from php not listening

Hello,

I have a problem with echo’d tables from php. Its a kinda hard to explain so this is the working page:

[URL=”http://www.maartenwelbergen.nl/v2/gallerij.php”] http://www.maartenwelbergen.nl/v2/gallerij.php
[/URL]

If you click on the + the description shows up. Again and it hides.

Now i want to have only one description open at the same time.
First i tryed to use an external javascript file but then i got the error:

[I]document.getElementById(“galTxt0”) has no properties.[/I]

I solved this problem by using onclick in the echo’d html code.

This is the html code echo’d by php:

[CODE]
for ($i=1;$i<count($ar_dirsInc);$i++) {
echo (‘
<table width=”100%” border=”0″ cellpadding=”0″ cellspacing=”0″>
<tr bgcolor=”#333333″>
<td>
<table width=”100%” height=”25″ border=”0″ cellpadding=”0″ cellspacing=”0″>
<tr>
<td bgcolor=”#333333″>’.$ar_dirsEx[$i].'</td>
<tdbgcolor=”#333333″ align=”right”>
<a style=”border:none” href=”javascript:;” onclick=”show_hide(‘galTxt’.$i.”)”>
<img src=”images/menu/gal_btn_plus.png” id=”galImg’.$i.'” width=”19″ height=”19″ border=”0″ />
</a>
</td>
</table>
</td>
</tr>
<tr id=”galTxt’.$i.'” style=”display:none”>
<td>
<table>
<tr>
<td width=”35%” align=”center”>
<img src=”admin/gallerij/’.$ar_dirsInc[$i].’/’.$ar_lastFiles[$i].'” height=”100″ />
</td>
<td width=”65%”>
‘.$textOne.’
</td>
</tr>
</table>
</td>
</tr>
</table>’);
[/CODE]

The onclick in the images triger this function:

[CODE]
function show_hide(tblid, show) {
if (tbl = document.getElementById(tblid)) {
if (null == show) show = tbl.style.display == ‘none’;
tbl.style.display = (show ? ” : ‘none’);
}
}[/CODE]

I tryed to change the function to:

[CODE]var allId = document.getElementById(“*”);
for (var i=0; i<allId.length; i++) {
if (allId[i].indexOf(“getTxt”) > -1) {
if (allId[i]==tblid) {
document.getElementById(tblid).style.display = ”;
} else {
document.getElementById(allId[i]).style.display = ‘none’;
}
}
}[/CODE]

but i get the error:

[I]allId has no properties.[/I]

Now i’m looking for a way to let the echo’d code listen to my external javascript or to change the function so it hides the description when i open another description.

Post here or pm me if you need more code/info.
Thanks for reading.

Greetings

Gert-Jan Rebel

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991Feb 25.2008 — I would say that you are not calling the code on onload?

window.onload = function() {

// All your code goes here.

}

The PHP is totally irrelevant.
Copy linkTweet thisAlerts:
@KorFeb 26.2008 — getElementById() returns [I]always[/I] a single element, not a collection, thus you can not use a wild card '*' as argument. You may use getElementsByTagName() instead:

<i>
</i>var allTags=document.getElementsByTagName('*'), i=0, elem;
while(elem=allTags[i++]){
if(elem.id.match(getTxt)){
elem.style.display=elem.id==tblid?'':'none';
}
}
Copy linkTweet thisAlerts:
@ParvulusauthorFeb 26.2008 — it works it works!! Thanks alot!!

maartenwelbergen.nl/v2/

under "Gallerij"
×

Success!

Help @Parvulus spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...