Reputation: 108
See I'm having this problem when i pass an argument from my database to a javascript function i get a number that decrements and also it's a different number from what i expect to show up
the format of what im passing is (####-####)
<?php
include 'connect.php';
session_start();
if(isset($_SESSION['name']) && $_SESSION['name'] != "")
{
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="css/main.css" />
<script src="js/main.js"></script>
</head>
<body>
<div id="TopContainer">
<div id="user">
<div id="msg">
<a href="logout.php">
<button type="button" style="width:60px;float:right;padding:5px;" class="submit">
Log Out
</button>
</a>
<span style="float:left;">
Hello, <?php echo $_SESSION['name']; ?>
</span>
</div>
</div>
<form action="main.php" method="POST" id="form" name="form">
<div id="box" name="box" style="-webkit-transition:1s;overflow:hidden;">
<label class="boxes"><input type="checkbox" id="All" name="All" onclick="checkAll()" /><span>All</span></label>
<label class="boxes"><input type="checkbox" id="books" name="books" onclick="rmOthers(1)"/><span>Books</span></label>
<label class="boxes"><input type="checkbox" id="journals" name="journals" onclick="rmOthers(2)"/><span>Journals</span></label>
<label class="boxes"><input type="checkbox" id="guidelines" name="guidelines" onclick="rmOthers(3)"/><span>Guidelines</span></label>
<label class="boxes"><input type="checkbox" id="pe" name="pe" onclick="rmOthers(4)"/><span>Patient Education</span></label>
</div>
<button type="button" class="submit" id="hide" style="padding:15px 20px;" onclick="hideBoxes()">+</button><input type="search" name="search" class="inputs" placeholder="Search Articles" value="<?php echo isset($_POST['search']) ? $_POST['search'] : ""; ?>" /><button type="submit" name="submit" class="submit" >Search</button><br />
<div id="sq">
<select id="sqType" style="width:5%;">
<option class="ar">And</option>
<option class="ar">Or</option>
</select>
<input type="search" class="inputs" placeholder="Filter Results" name="filter" style="width:70%;" value='<?php echo (isset($_POST['filter']) ? $_POST['filter'] : ''); ?>' />
<button type='submit' id="fil" name='btn_filter' class="submit" style="-webkit-transform:translateX(-5px) translateY(-3px); width:7%;" >Filter</button>
</div>
</form>
</div>
<br /><br /><br /><br /><br /><br /><br /><br />
<div id="BottomContainer">
<?php
if((isset($_POST['submit'])) || (isset($_POST['btn_filter'])))
{
$search = mysqli_real_escape_string($con,$_POST['search']);
$sql = (strcmp($search, "") == true ? "SELECT * FROM tbl_additionals JOIN tbl_general_info WHERE tbl_general_info.reference_number LIKE '%$search%' OR tbl_general_info.title LIKE '%$search%' OR tbl_general_info.author LIKE '%$search%' OR tbl_additionals.abstract LIKE '%$search%'" : "SELECT * FROM tbl_additionals JOIN tbl_general_info WHERE tbl_general_info.reference_number LIKE '%$search%' OR tbl_general_info.title LIKE '%$search%' OR tbl_general_info.author LIKE '%$search%' OR tbl_additionals.abstract LIKE '%$search%' LIMIT 30");
$query = mysqli_query($con, $sql);
if(mysqli_num_rows($query) != 0)
{
while($run = mysqli_fetch_assoc($query))
{
$reference = (string)$run['reference_number'];
$title = (strlen($run['title']) > 121) ? substr($run['title'], 0, strpos(wordwrap($run['title'], 121), "\n")) . '...' : $run['title'];
echo '<div class="SearchResults">';
echo " <span class='top'>";
echo " <a>";
echo " <h3>". strtoupper($title) ."</h3>";
echo " </a>";
echo " <br />";
echo " <h5 class='sub'>";
echo $run['reference_number'];
echo " Authors :<a class='authors'>Dr.Michael Ramsay</a><a class='authors'>Dr.Lars Benitez</a><a class='authors'>Dr.Kevin John Pascual</a><br><br>";
echo " </h5>";
echo " </span>";
echo " <span class='bottom'>";
echo " <span class='bottomLeft'>";
echo ($run['abstract'] != "" ? " <a class='options' onclick='showOverlay(".$reference.")'>Abstract</a><span style='margin:0px 5px;'>|</span>" : "" );
echo " <a target='_blank' href='view.php?filename=NKTI Proceedings vol. 1 no. 1 Feb. 1996' class='options'>";
echo " Full Article";
echo " </a>";
echo " </span>";
echo " <div class='overlay' id='". $run['reference_number'] ."' onclick='hideOverlay(this, event)'> ";
echo " <iframe class='abstract' src='abstract.php?id=".$run['reference_number']."' style='padding:0px;' scrolling='no'>";
echo " </iframe>";
echo " </div>";
echo " <span class='bottomRight'>";
echo " <p class='label'>NKTI Proceedings volume 1, January - April 2015 @ Pg. 1-15</p>";
echo " </span>";
echo " </span>";
echo " <br style='clear:both;'/>";
echo "</div>";
}
}
}
?>
</div>
</body>
</html>
<?php
}
else
{
echo "<script>alert('Please Login To Continue');window.open('index.php','_self');</script>";
}
?>
here's my javascript code
function showOverlay(id)
{
alert(id);
document.getElementById(id).style['display'] = "block";
document.getElementById(id).style['opacity'] = "1";
}
i just made that alert statement just so i can see what the program is passing on javascript here's what happens
i clicked on the first abstract link that showed up as you can see i echoed out that should be passed before the authors then what is passed is on the alert box
i cant seem to find what's wrong here is it my mysql statement or the javascript code or the php code
Upvotes: 2
Views: 84
Reputation: 749
Add the ID to the Abstract link and change showOverlay(".$reference.")
to onclick='showOverlay(this.dataset.articlenum)'
See the line in PHP below:
echo ($run['abstract'] != "" ? "<a class='options' data-articlenum='" . $reference . "' onclick='showOverlay(this.dataset.articlenum)'>Abstract</a><span style='margin:0px 5px;'>|</span>" : "" );
Fiddle: http://jsfiddle.net/codyogden/0eea7gxw/
Upvotes: 1