hi, I have a problem with my javascript function.. this the code
<?php
include("include/connection.php");
if(isset($_GET['id'])){
if(isset($_COOKIE["users_resolution"])){
$resWidth = $_COOKIE["users_resolution"]-17;
}else{
echo "<script language='javascript'>";
echo "writeCookie();";
echo "function writeCookie()";
echo "{";
echo "var today = new Date();";
echo "var the_date = new Date('December 31, 2023');";
echo "var the_cookie_date = the_date.toGMTString();";
echo "var the_cookie = 'users_resolution='+ screen.width;";
echo "var the_cookie = the_cookie + ';expires=' + the_cookie_date;";
echo "document.cookie=the_cookie;";
echo "location = 'topic.php';";
echo "}";
echo "</script>";
}
$id_topik=$_GET['id'];
$query="SELECT * FROM topik WHERE id=".$id_topik;
$result=mysql_query($query,$connection);
if(mysql_num_rows($result)>0){
while($row=mysql_fetch_assoc($result)){
$judulPost=$row['judul'];
$isiPost=$row['isi'];
$isiPost=str_replace("*","'",$isiPost);
$isiPost=str_replace('#','"',$isiPost);
$authorPost=$row['author'];
$kategoriId=$row['id_kategori'];
$tanggalPost=$row['tanggal'];
$tanggalPost=date('d F Y',strtotime($tanggalPost));
$keyword=$row['keyword'];
$arrKey=explode(",",$keyword);
$keywordPost="";
for($i=0;$i<count($arrKey);$i++){
$keywordPost=$keywordPost."<a href='search.php?keyword=".$arrKey[$i]."' class='linkKeyword'>".$arrKey[$i]."</a>";
if ($i<count($arrKey)-1){
$keywordPost=$keywordPost.", ";
}
}
}
mysql_free_result($result);
}
$query="SELECT * FROM kategori WHERE id=".$kategoriId;
$result=mysql_query($query,$connection);
if(mysql_num_rows($result)>0){
while($row=mysql_fetch_assoc($result)){
$kategoriPost=$row['nama'];
}
mysql_free_result($result);
}
if(isset($_COOKIE['username'])){
$user=$_COOKIE['username'];
}
}
else{
header("location:index.php");
}
?>
<html>
<head>
<link rel="stylesheet" href="css/skripsi.css" type="text/css">
<link rel="stylesheet" type="text/css" href="css/ddsmoothmenu-v.css" />
<link rel="stylesheet" href="css/slidingdoors/simple-sliding-doors.css" type="text/css" media="screen">
<script src="js/jquery-1.4.2.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">document.documentElement.className += " js";</script>
<script src="js/tab/jquery.tabs.js" type="text/javascript" charset="utf-8"></script>
<script src="js/tab/jquery.syncheight.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="js/ddsmoothmenu.js">
<script type="text/javascript" language="JavaScript" src="js/functions.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var tabs = $("#tabs1").accessibleTabs({
tabhead:'h2',
fx:"fadeIn",
syncheights:true
});
$.get('ajax/high-score.php',{
id_topik:<?php echo $id_topik; ?>
},function(data){
$('#highScore').html(data);
});
});
ddsmoothmenu.init({
mainmenuid: "smoothmenu2", //Menu DIV id
orientation: 'v', //Horizontal or vertical menu: Set to "h" or "v"
classname: 'ddsmoothmenu-v', //class added to menu's outer DIV
//customtheme: ["#804000", "#482400"],
contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
});
function commentPost_1(){
var comment=window.document.getElementById("txtComment").value;
comment = comment.replace(/\n/g,"<br />");
comment = comment.replace("'","*");
comment = comment.replace('"','#');
if(comment!=""){
$.get('ajax/comment.php',{
username:'<?php echo $user; ?>',email:($('#txtEmailComment').val()),comment:comment,id_topik:<?php echo $id_topik; ?>,author:'<?php echo $authorPost; ?>'
},function(data){
$('#commentPost').html(data);
});
}
window.document.getElementById("txtComment").value="";
}
function commentPost_2(){
alert('aaa');
}
function deletePost(id_komentar){
if (confirm("Apakah Anda yakin untuk komentar ini?")) {
$.get('ajax/comment-delete.php',{
id_komentar:id_komentar,id_topik:<?php echo $id_topik; ?>,author:'<?php echo $authorPost; ?>'
},function(data){
$('#commentPost').html(data);
});
}
}
</script>
<style>
#Wrapper,#Container,#foorarea{
width:<?php echo $resWidth; ?>px;
}
</style>
</head>
<body>
<div id="Wrapper">
<div id="Container">
<!-- Header -->
<div id='upMenu'>
<?php
include("include/header.php");
?>
</div>
<!-- Header End -->
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td id="LeftColumn">
<a href="index.php"><img src="images/logo.jpg"></a>
<p><div id="isiLeftColumn1">
<?php
include("include/menu-left.php");
?>
</div></p>
<div id="isiLeftColumn2">
<div id="headlinesBg">
<div class="judulHeadlines" style="float:left;">Baca Topik</div>
<div style="float:right;padding-right:3%;">
<input type="text" class="txtboxSearch">
<input type="button" class="btnStyle" value="Search">
</div><br><br>
</div>
<div id="isiContent" style="background-image:url(images/line.png);width:550px;padding-top:5px;">
<div style="font-size:15pt;font-weight:bold;color:#9b3829;padding-left:4.5%;">
<?php echo $judulPost; ?>
</div>
<hr style="margin-left:4.5%;margin-right:4.5%">
<div style="padding-left:4.5%;font-size:8pt;color:#909090">
<?php echo $tanggalPost; ?> - Kategori: <a href='kategori.php?id=<?php echo $kategoriId; ?>' class="linkKeyword"><?php echo $kategoriPost; ?></a>
</div>
<p style="padding-left:4.5%;margin-right:4.5%;font-size:9pt;">
<?php echo $isiPost; ?>
</p>
<div style="float:right;padding-right:4.5%;">
<input type="button" value="Jawab Pertanyaan" class="btnStyle">
</div>
<div style="clear:both"></div>
<div style="margin-top:3%;padding-left:4.5%;font-size:8pt;color:#909090">
Keywords: <?php echo $keywordPost; ?>
</div>
<div style="height:40px;margin-top:3%;margin-left:4.5%;margin-right:4.5%;padding:2%;background-color:#cccbc0;font-size:10pt">
<img src="profile/thumbs/a71ac4ca0311cecc9f22c367c975f167.jpg" style="position:absolute;width:40px;clip:rect(0px 40px 40px 0px)">
<span style="padding-left:10.5%">Author:
<span style="color:#9b3829">
<a href='profile.php?id=<?php echo md5($authorPost); ?>' class='judulKat'><?php echo $authorPost; ?></a>
</span>
</span>
</div>
<div style="margin-top:2.5%;margin-left:4.5%;margin-right:4.5%;font-size:9pt;">
Add New Comment
</div>
<?php
$blank="blank";
if(isset($_COOKIE['username'])){
echo "<div style='height:40px;margin-top:2.5%;margin-left:4.5%;margin-right:4.5%;'>";
echo "<img src='profile/thumbs/";
$filename = "profile/thumbs/".md5($_COOKIE['username']).".jpg";
if (file_exists($filename)) {
echo md5($_COOKIE['username']);
} else {
echo md5($blank);
}
echo ".jpg' style='position:absolute;width:40px;clip:rect(0px 40px 40px 0px)'>";
echo "<textarea class='txtArea3' id='txtComment' name='txtComment'></textarea>";
echo "</div>";
echo "<div style='float:right;padding-right:4.5%;'>";
echo "<input type='button' value='Comment' class='btnStyle' onClick='commentPost_1()'>";
echo "</div>";
}
else{
echo "<div style='height:95px;margin-top:2.5%;margin-left:4.5%;margin-right:4.5%;'>";
echo "<img src='profile/thumbs/".md5($blank).".jpg' style='margin-top:0.4%;position:absolute;width:40px;clip:rect(0px 40px 40px 0px)'>";
echo "<input style='margin-left:10%;' type='text' id='txtNamaComment' name='txtNamaComment'>";
echo "<span style='padding-left:1%;font-size:8pt'>Nama</span>";
echo "<br>";
echo "<input style='margin-left:10%;' type='text' id='txtEmailComment' name='txtEmailComment'>";
echo "<span style='padding-left:1%;font-size:8pt'>Email (tidak akan ditampilkan)</span>";
echo "<br>";
echo "<textarea class='txtArea3' style='margin-top:0.5%;' id='txtComment2' name='txtComment2'></textarea>";
echo "</div>";
echo "<div style='float:right;padding-right:4.5%;'>";
echo "<input type='button' value='Comment' class='btnStyle' onClick='commentPost_2()'>";
echo "</div>";
}
?>
<div style="clear:both"></div>
<div id="commentPost">
<?php
$blank="blank";
$query="SELECT * FROM komentar WHERE id_topik=".$id_topik;
$result=mysql_query($query,$connection);
if(mysql_num_rows($result)>0){
while($row=mysql_fetch_assoc($result)){
echo "<table style='margin-bottom:10px;'>";
if($row['username']<>""){
echo "<tr>";
echo "<td width='45' style='padding-top:7px;vertical-align:top' rowspan='3'>";
echo "<img src='profile/thumbs/";
$filename = "profile/thumbs/".md5($row['username']).".jpg";
if (file_exists($filename)) {
echo md5($row['username']);
} else {
echo md5($blank);
}
echo ".jpg' style='position:absolute;width:40px;clip:rect(0px 40px 40px 0px)'>";
echo "</td>";
echo "<td style='font-size:9pt;font-weight:bold;'>";
echo "<hr style='width:445px'>";
echo "<span style='color:#9b3829'><a href='profile.php?id=".md5($row['username'])."' class='judulKat'>".$row['username']."</a></span>";
if(isset($_COOKIE['username'])){
if ($authorPost==$user || $user==$row['username']){
echo "<span style='float:right'>";
echo "<img src='images/delete.png' title='Delete' style='cursor:pointer' onClick='deletePost(".$row['id'].")'>";
echo "</span>";
echo "<span style='clear:both'></span>";
}
}
echo "</td>";
echo "</tr>";
}
else{
echo "<tr>";
echo "<td width='45' style='padding-top:7px;vertical-align:top' rowspan='3'>";
echo "<img src='profile/thumbs/".md5($blank).".jpg' style='position:absolute;width:40px;clip:rect(0px 40px 40px 0px)'>";
echo "</td>";
echo "<td style='font-size:9pt;font-weight:bold;'>";
echo "<hr style='width:445px'>";
echo "<span style='color:#505050'>".$row['nama'];
if(isset($_COOKIE['username'])){
if ($authorPost==$user){
echo " (<a style='color:#505050' href='mailto:".$row['email']."'>".$row['email']."</a>)";
}
}
echo "</span>";
if(isset($_COOKIE['username'])){
if ($authorPost==$user){
echo "<span style='float:right'>";
echo "<img src='images/delete.png' title='Delete' style='cursor:pointer' onClick='deletePost(".$row['id'].")'>";
echo "</span>";
echo "<span style='clear:both'></span>";
}
}
echo "</td>";
echo "</tr>";
}
echo "<tr>";
echo "<td style='font-size:8pt;color:#909090;'>";
echo date('d F Y, h:i A',strtotime($row['waktu']));
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td style='font-size:9pt;'>";
echo "<hr style='width:445px'>";
$komentar=$row['komentar'];
$komentar=str_replace("*","'",$komentar);
$komentar=str_replace('#','"',$komentar);
echo $komentar;
echo "</td>";
echo "</tr>";
}
echo "</table>";
mysql_free_result($result);
}
?>
</div>
</div>
</div>
</td>
<td id="RightColumn">
<?php
include("include/menu-right.php");
?>
</td>
</tr>
</table>
</div>
<!-- Container End -->
<!-- Footer -->
<div id='footarea'>
<?php
include("include/footer.php");
?>
</div>
<!-- Footer End -->
</div>
<!-- Wrapper End -->
<!-- Switch Contents -->
</body>
</html>
I can't execute function commentPost_2(), but, if I delete function commentPost_1(), commentPost_2() can execute the alert('aaa')
what happen with my code :(.. thanks for your advice.. :)