I am trying to pass a php array to The JavaScript Function FindCheckBoxes(Test)
using onClick
functionality. But this code does not seem to work. It Seems like JSON_ENCODING
is not working.
How do I pass my $array variable to the JavaScript Function. I have searched the internet but can't get it to work. That is, alert spits out nothing(a blank). I want '$array' parameters to be there Here is my code:
<!DOCTYPE html>
<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6 lt8"> <![endif]-->
<!--[if IE 7 ]> <html lang="en" class="no-js ie7 lt8"> <![endif]-->
<!--[if IE 8 ]> <html lang="en" class="no-js ie8 lt8"> <![endif]-->
<!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
<head>
<meta charset="UTF-8" />
<!-- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> -->
<title>Login and Registration Form with HTML5 and CSS3</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Facebook Timeline" />
<meta name="keywords" content="html5, css3, form, switch, animation, :target, pseudo-class" />
<meta name="author" content="Codrops" />
<link rel="shortcut icon" href="../favicon.ico">
<link rel="stylesheet" type="text/css" href="css/demo.css" />
<link rel="stylesheet" type="text/css" href="css/style1.css" />
<link rel="stylesheet" type="text/css" href="css/animate-custom.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
<?php
$array =array();
array_push($array,"aa");
?>
function comment(){
var jFirst = document.getElementById("usernamesignup").value;
alert("Your name is: "+ jFirst);
}
function findCheckedBoxes(test) {
alert("here");
var select_array= new Array();
alert(test);
var AllBoxes = $(".pp");
for(i=0;i<AllBoxes.length;i++)
{
if(AllBoxes[i].checked)
{
select_array.push(foo[i]);
}
}
alert(select_array);
return true;
}
</script>
</head>
<body>
<?php
//PostID = 0 means its not a constraint
function comment($pauthor, $author, $substr, $start, $postid, $end) {
$q = "select * from Comment where Author like '".$author."%' and Text like '%".$substr."%' and Time >= '".$start."' and Time <= '".$end."' and (PostID = ".strval($postid)." or ".strval($postid)." = 0) and PostID in (select PostID from Post where Author like '".$pauthor."%')";
return $q;
}
function user($user, $pre, $post, $sepr) {
if($user == 1) return $pre."1".$post.$sepr.$pre."2".$post.$sepr.$pre."3".$post;
if($user == 2) return $pre."2".$post.$sepr.$pre."3".$post;
//if($user == 3)
return $pre."3".$post;
}
function comb($q1, $q2, $q3) {
$str = "'000'";
for($i = $q1; $i <= 3; $i++) {
for($j = $q2; $j <= 3; $j++) {
for($k = $q3; $k <= 3; $k++) {
$str = $str.", '".strval($i).strval($j).strval($k)."'";
}
}
}
return $str;
}
function perm($g1, $g2, $g3,$union,$user) {
if($union) {
if($g1 && $g2 && $g3) //return "Permission_bits like %3% or Permission_bits like %2% or Permission_bits like %1%";
return user($user, "Permission_bits like '%", "%'", " or ");
if($g1 && $g2) return user($user, "Permission_bits like '", "__'", " or ").user($user, "Permission_bits like '_", "_'", " or ");
if($g2 && $g3) return user($user, "Permission_bits like '__", "'", " or ").user($user, "Permission_bits like '_", "_'", " or ");
if($g1 && $g3) return user($user, "Permission_bits like '", "__'", " or ").user($user, "Permission_bits like '__", "'", " or ");
if($g1) return user($user, "Permission_bits like '", "__'", " or ");
if($g2) return user($user, "Permission_bits like '_", "_'", " or ");
if($g3) return user($user, "Permission_bits like '__", "'", " or ");
return "Permission_bits = '000'";
} else {
if($g1 && $g2 && $g3) return "Permission_bits in (".comb($user, $user, $user).")";
if($g1 && $g2) return "Permission_bits in (".comb($user, $user, 0).")";
if($g2 && $g3) return "Permission_bits in (".comb(0, $user, $user).")";
if($g1 && $g3) return "Permission_bits in (".comb($user, 0, $user).")";
if($g1) return "Permission_bits in (".comb($user, 0, 0).")";
if($g2) return "Permission_bits in (".comb(0, $user, 0).")";
if($g3) return "Permission_bits in (".comb(0, 0, $user).")";
return "Permission_bits = '000'";
}
}
?>
<?php
$author=$_REQUEST['author'];
$pauthor=$_REQUEST['post_author'];
$text=$_REQUEST['text'];
$start=$_REQUEST['start'];
$end=$_REQUEST['end'];
?>
<div class="container">
<!-- Codrops top bar -->
<div class="codrops-top">
<span class="right">
</span>
<div class="clr"></div>
</div><!--/ Codrops top bar -->
<header>
<h1>FACEBOOK TIMELINE</h1>
</header>
<section>
<div id="container_demo" >
<!-- hidden anchor to stop jump http://www.css3create.com/Astuce-Empecher-le-scroll-avec-l-utilisation-de-target#wrap4 -->
<a class="hiddenanchor" id="toregister"></a>
<a class="hiddenanchor" id="tologin"></a>
<div id="wrapper">
<div id="login" class="animate form">
<form action="comments.php" autocomplete="on">
<h1>COMMENTS</h1>
<br>
<br>
<TABLE>
<td>
</td>
<td>
<img src="comments.jpg" align="center" width=400>
</td>
<td>
<FORM id="FORM" action="comments.php" method="post">
<INPUT TYPE="submit" id="1" VALUE="START A NEW SEARCH HERE " >
</FORM>
</td>
</TABLE>
<br>
<br>
<TABLE BORDER="0" WIDTH=200px ALIGN=CENTER>
<tr>
<h1>YOUR RESULTS</h1>
<INPUT TYPE="button" onClick="findCheckedBoxes('<?php json_encode($array); ?>')" VALUE="CHANGE PERMISSION TO GROUP MEMBERS ONLY" />
<INPUT TYPE="button" onclick="findCheckedBoxes()" VALUE="CHANGE PERMISSION TO YOUR FRIENDS ONLY"/>
<INPUT TYPE="button" onclick="findCheckedBoxes()" VALUE="CHANGE PERMISSION TO EVERYBODY" />
<?php
//echo '<FORM id="MYFORM0" onsubmit="return findCheckedBoxes()" >
//</FORM>.<br>.<br>';
// Connects to your Database
mysql_connect("10.142.233.33", "root", "limiwisn") or die(mysql_error());
//mysql_connect("", "root", "guitar") or die(mysql_error());
$count=0;
mysql_select_db("Ass3") or die(mysql_error());
$datai = mysql_query(comment($pauthor, $author, $text, $start, 0, $end))
or die(mysql_error());
while($infoi = mysql_fetch_array( $datai ))
{
$count = $count + 1;
}
echo '<tr><td><font size=5>';
echo "Total number of Comments ->".strval($count)."<br><br>";
echo '</tr></td></font>';
echo "<br>";
mysql_select_db("Ass3") or die(mysql_error());
$datai = mysql_query(comment($pauthor, $author, $text, $start, 0, $end))
or die(mysql_error());
echo '<tr><td><font size=4>';
while($infoi = mysql_fetch_array( $datai ))
{
echo $infoi['CommentID']."<br>";
echo '<input type="checkbox" class="pp" name="sdfsdg" value="my_checkbox"/>'.'<br>';
echo $infoi['Author']."<br>";
echo $infoi['Text']."<br>";
echo $infoi['Time']."<br><br><br>";
array_push($array,$infoi['CommentID']);
}
echo "<br>";
echo '</td></tr></font>';
echo '</table>';
print_r ($array);
?>
<br>
<br>
</form>
</div>
</div>
</div>
</section>
</div>
</body>
</html>