Page 1 of 1

Not displaying a <a>?

Posted: Tue Aug 09, 2011 1:44 pm
by ThatPerson
My code is far below and should display a side bar which has hyperlinks which run some Javascript, however it only displays the search, log out, and settings buttons, not the <a> text.

Code: Select all

<?php
ob_start();
include("database.php");
#JavaScript
echo <<<END
<head>
<script language="javascript">
  function hideAll(divid){
   document.getElementById(nte1).style.display = 'none';
   document.getElementById(nte2).style.display = 'none';
   document.getElementById(nte3).style.display = 'none';
   document.getElementById(nte4).style.display = 'none';
   document.getElementById(nte5).style.display = 'none';
   document.getElementById(nte6).style.display = 'none';
   document.getElementById(divid).style.display = 'block';
  }
</script>
</head>
END;
#Setting variables, to make life easy
if (isset($_COOKIE['loggeduser']) and isset($_COOKIE['loggedpass'])) {
$usr = $_COOKIE['loggeduser'];
$pwd = $_COOKIE['loggedpass'];
} else {
echo <<<END
<head>
<meta HTTP-EQUIV="REFRESH" content="0; url='../login.php'">
</head>
END;
}
$sidepanel = "images/side.gif";
$buttons = "images/side.gif";
$background = "images/back.jpg";
$notes = "images/notes.jpg";
$p = 0;
$note1 = mysql_fetch_object(mysql_query("select note1 from barker_users where users = '$usr' and password = '$pwd'"))->note1;
$note2 = mysql_fetch_object(mysql_query("select note2 from barker_users where users = '$usr' and password = '$pwd'"))->note1;
$note3 = mysql_fetch_object(mysql_query("select note3 from barker_users where users = '$usr' and password = '$pwd'"))->note1;
$note4 = mysql_fetch_object(mysql_query("select note4 from barker_users where users = '$usr' and password = '$pwd'"))->note1;
$note5 = mysql_fetch_object(mysql_query("select note5 from barker_users where users = '$usr' and password = '$pwd'"))->note1;
$note6 = mysql_fetch_object(mysql_query("select note6 from barker_users where users = '$usr' and password = '$pwd'"))->note1;
$note1name = mysql_fetch_object(mysql_query("select note1name from barker_users where users = '$usr' and password = '$pwd'"))->note1;
$note2name = mysql_fetch_object(mysql_query("select note2name from barker_users where users = '$usr' and password = '$pwd'"))->note1;
$note3name = mysql_fetch_object(mysql_query("select note3name from barker_users where users = '$usr' and password = '$pwd'"))->note1;
$note4name = mysql_fetch_object(mysql_query("select note4name from barker_users where users = '$usr' and password = '$pwd'"))->note1;
$note5name = mysql_fetch_object(mysql_query("select note5name from barker_users where users = '$usr' and password = '$pwd'"))->note1;
$note6name = mysql_fetch_object(mysql_query("select note6name from barker_users where users = '$usr' and password = '$pwd'"))->note1;

#Code for the side panel
echo <<<END
<div style="height:98%;width:20%;top:1%;left:0%;position:absolute;background:url($sidepanel) no-repeat;background-size:100%;">
 <div style="height:80%;width:90%;top:10%;left:0%;background-color:#FFFFFF;">
  <FORM NAME ="form1" METHOD ="POST" ACTION = "test.php">
  <a onclick="hideAll(nte1)" style="background:url('$buttons');height:11%;width:100%;top:0%;">$note1name</a>
  <a onclick="hideAll(nte2)" style="background:url('$buttons');height:11%;width:100%;top:11%;">$note2name</a>
  <a onclick="hideAll(nte3)" style="background:url('$buttons');height:11%;width:100%;top:22%;">$note3name</a>
  <a onclick="hideAll(nte4)" style="background:url('$buttons');height:11%;width:100%;top:33%;">$note4name</a>
  <a onclick="hideAll(nte5)" style="background:url('$buttons');height:11%;width:100%;top:44%;">$note5name</a>
  <a onclick="hideAll(nte6)" style="background:url('$buttons');height:11%;width:100%;top:55%;">$note6name</a>

  <div style="height:11%;width:100%;top:66%;background:url("$buttons");">
   <input type="Text" name="search" value="Search">
   <input type="Submit" name="searchbutton" value="Search">
  </div>
 <input onclick="hideAll(settings)" type="Submit" name="settings" value="Settings" style="background:url('$buttons');height:11%;width:100%;top:77%;">
 <input type="Submit" name="logout" value="Log Out" style="background:url('$buttons');height:11%;width:100%;top:88%;">
 </div>
</div>
END;
echo <<<END
<div style="position:absolute;height:90%;width:70%;top:5%;left:25%;background:url('$notes') no-repeat;background-size:100%;">
END;
$p = 0;
 for ($i = 1; $i <= 8; $i++) {
   $p=$p+1;
   $button = "update".$p; 
   $subject = "subject".$p; 
   $note = "text".$p; 
   $text = ${"note".$p};
   $subjecttext = ${"note".$p."name"};
   $id = "nte".$p;
echo <<<END
 <div style="height:100%;width:100%;top:0%;left:0%;background:url('$notes') no-repeat;background-size:100%;display:none; background-color:yellow;" id = "$id">
  <FORM NAME ="form1" METHOD ="POST" ACTION = "test.php">
  <input type="Submit" name="$button" value="Update" style = "height:10%;width:30px;left:50%;top:5%;">
  <input type="Text" name="$subject" value="$subjecttext" style = "height:10%;width:35%;left:5%;top:5%;">
  <input type="Text" name="$note" value="$text" style = "height:75%;width:90%;left:5%;top:10%;">
 </div>
END;
 }
echo <<<END
 <div style="height:100%;width:100%;top:0%;left:0%;background:url('$notes') no-repeat;background-size:100%;display:none;" id = "settings">
  <FORM NAME ="form1" METHOD ="POST" ACTION = "notepad.php">
 </div>
END;
?>

Re: Not displaying a <a>?

Posted: Tue Aug 09, 2011 3:26 pm
by social_experiment
Try adding href="" to the anchors.

Re: Not displaying a <a>?

Posted: Wed Aug 10, 2011 1:40 am
by Dodon
I copied <a onclick="hideAll(nte6)" style="background:url('$buttons');height:11%;width:100%;top:55%;">$note6name</a> and pasted it in a plain html document and it shows the link properly. So it shows the text on the screen. Are you sure that $note1name to $note6name contains a value?

Also in order to make the link clickable do what social_experiment says, add the href="". In order to not switch pages when you click the link you can add return false to your onclick event like this: onclick="hideAll(nte1); return false;"

Btw check the source code generated by the browser and see if the hyperlink is showing up in there, if the hyperlink in the source code looks something like this:

<a onclick="hideAll(nte6)" style="background:url('images/side.gif);height:11%;width:100%;top:55%;"></a>

then $note1name doesn't contain a value and thus not generating any text.

Re: Not displaying a <a>?

Posted: Wed Aug 10, 2011 2:03 am
by ThatPerson
Ah, thanks for the replies. I had a look in the 'Inspect Element' thing in Chromium, and saw that it has no text. I have since added a if statement which checks if the notes have names, if so it displays them.