/    Sign up×
Community /Pin to ProfileBookmark

Javascript not working on PHP page

Howdy folks… the code for my page is below and the website that it is currently viewable on is : [url]http://scott.loddonexplorers.co.uk/contacts.php[/url]

1) The only data i should see is the list of names and there email address. I currently get the expanded view…
2) When i click a button which should be visable to the left of the name, it should show all data, but the button currently dosent show, neither does it work when i click it… but all the data is viewable.. any ideas?

Fet

[code=php]
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”
“http://www.w3.org/TR/html4/loose.dtd”>
<html>
<head>
<title>Leaders</title>
<meta http-equiv=”content-type” content=”text/html; charset=iso-8859-1″ />
<link rel=”stylesheet” type=”text/css” href=”css/phpdisplay.css” />

<script type=”text/javascript”>
function showDetails(memberID,button){
var element = document.getElementById(memberID);
if(element.style.display != ‘block’){
element.style.display = ‘block’;
button.style.backgroundImage = ‘url(“images/minus.gif”)’;
}else{
element.style.display = ‘none’;
button.style.backgroundImage = ‘url(“images/plus.gif”)’;
}
}
</script>
</head>
<body>
<div>
<?php
$connx = mysql_connect(“localhost”, “root”, “admin”) or
die(“ERROR: Unable to establish database connection”);

$dbconnx = mysql_select_db(‘Main’) or
die(“ERROR: Unable to establish database connection”);

?>
<p class=”title”>Leader Team</p>
<blockquote>
<?php

$result = mysql_query(‘SELECT * FROM `Contacts` GROUP BY `ID`’) or
die(‘<p>Error performing query: ‘ . mysql_error() . ‘</p>’);

echo ‘<div id=”alldetails”>’;
$i = 0;

while($row = mysql_fetch_row($result))
{
echo <<<END
<p><input type=”image” class=”button” id=”button$i” value=” ” onclick=”showDetails(‘person$i’,this);return true;”> {$row[2]} {$row[3]} <a href=”mailto:{$row[9]}”>{$row[9]}</a></p>
<p id=”person$i” class=”details”>
<table width=”800″ border=”0″>
<tr>
<td><b>Name:</b></td>
<td>{$row[2]} {$row[3]}<br></td>
</tr>
<tr>
<td><b>Address:</b></td>
<td>{$row[4]}<br></td>
</tr>
<tr>
<td><b>Town:</b></td>
<td>{$row[5]}<br></td>
</tr>
<tr>
<td><b>Postcode:</b></td>
<td>{$row[6]}<br></td>
</tr>
<tr>
<td><b>Home Phone:</b></td>
<td>{$row[7]}<br></td>
</tr>
<tr>
<td><b>Mobile:</b></td>
<td>{$row[8]}<br></td>
</tr>
<tr>
<td><b>Email:</b></td>
<td>{$row[9]}<br></td>
</tr>
</table>
END;

$i++;

}

?></div>
</blockquote>
</div>

</body>
</html>
[/code]

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@chazzyFeb 21.2006 — can you verify that your JS works on a regular HTML page (ie its static)
Copy linkTweet thisAlerts:
@scottyrobauthorFeb 21.2006 — O god, how would i go abotu doing that? lol
Copy linkTweet thisAlerts:
@NogDogFeb 21.2006 — Not sure, but I think the strings/variables in red below should be the same?
<i>
</i>&lt;p&gt;&lt;input type="image" class="button" id="[color=red]button$i[/color]" value=" "
onclick="showDetails('[color=red]person$i[/color]',this);return true;"&gt; {$row[2]} {$row[3]} &lt;a
Copy linkTweet thisAlerts:
@mobtexFeb 21.2006 — i had a javascript problem on [URL=http://www.mobtex.net/contact-us/]this page[/URL] If you click 'Business Inquiry' it shows the form where you can then enter a UK postcode and it will find the address for you. At first it was working okay in IE but not in FF - as soon as I added this header to the page it worked fine on both:

header("Content-type: text/html; charset=utf-8");

I'm not sure if it will help but for what it is it's worth trying.

Hope this helps, I also hope root and admin aren't really your user/pass combo! ?
Copy linkTweet thisAlerts:
@felgallFeb 21.2006 — They also need to be included between PHP tags as where you have them they are regular HTML and so the $i will be treated as $i and not as the value of that field.
Copy linkTweet thisAlerts:
@scottyrobauthorFeb 21.2006 — Nope that did nothing, except make the buttons work even worse than they already do!

Fet
Copy linkTweet thisAlerts:
@HuevoosFeb 22.2006 — [code=php]
while($row = mysql_fetch_row($result))
{
echo <<<END
<p><input type="image" class="button" id="button$i" value=" " onclick="showDetails('person$i',this);return true;"> {$row[2]} {$row[3]} <a href="mailto:{$row[9]}">{$row[9]}</a></p>
<p id="person$i" class="details">
<table width="800" border="0">
<tr>
<td><b>Name:</b></td>
<td>{$row[2]} {$row[3]}<br></td>
</tr>
<tr>
<td><b>Address:</b></td>
<td>{$row[4]}<br></td>
</tr>
<tr>
<td><b>Town:</b></td>
<td>{$row[5]}<br></td>
</tr>
<tr>
<td><b>Postcode:</b></td>
<td>{$row[6]}<br></td>
</tr>
<tr>
<td><b>Home Phone:</b></td>
<td>{$row[7]}<br></td>
</tr>
<tr>
<td><b>Mobile:</b></td>
<td>{$row[8]}<br></td>
</tr>
<tr>
<td><b>Email:</b></td>
<td>{$row[9]}<br></td>
</tr>
</table>
</p>
END;

$i++;

}
[/code]


You didnt close the paragraph
Copy linkTweet thisAlerts:
@scottyrobauthorFeb 22.2006 — Closed the paragraph but still, no change!
Copy linkTweet thisAlerts:
@HuevoosFeb 22.2006 — Can I see your current code???
×

Success!

Help @scottyrob 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.16,
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,
)...