The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. July 29, 2010, 07:56:20 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Including Javascript files amidst <?php ?> tags  (Read 361 times)
Keebler
Rookie
**
Offline Offline

Posts: 18


View Profile
« on: January 13, 2010, 05:39:13 AM »

This has been driving me nuts for the last several hours.

I am using Xampp and running files on localhost.

Basically I have a php script that gets some numbers from a database and outputs them as a list.

Now I have a drag and drop javascript that is supposed to make it so that you can drag and drop the separate items on the list into a different order.

The script:

Code:
<?php include 'accesscontrol.php'?>
<link rel="stylesheet" type="text/css" href="common/common.css"/>
<link rel="stylesheet" type="text/css" href="common/lists.css"/>


<script type="text/javascript" src="../source/org/tool-man/core.js"></script>
<script type="text/javascript" src="../source/org/tool-man/events.js"></script>
<script type="text/javascript" src="../source/org/tool-man/css.js"></script>
<script type="text/javascript" src="../source/org/tool-man/coordinates.js"></script>
<script type="text/javascript" src="../source/org/tool-man/drag.js"></script>
<script type="text/javascript" src="../source/org/tool-man/dragsort.js"></script>
<script type="text/javascript" src="../source/org/tool-man/cookies.js"></script>
<script type="text/javascript"><!--
 
  var dragsort = ToolMan.dragsort()
var junkdrawer = ToolMan.junkdrawer()

window.onload = function() {
junkdrawer.restoreListOrder("numeric")
junkdrawer.restoreListOrder("phonetic1")
junkdrawer.restoreListOrder("phonetic2")
junkdrawer.restoreListOrder("phonetic3")
junkdrawer.restoreListOrder("phoneticlong")
junkdrawer.restoreListOrder("boxes")
junkdrawer.restoreListOrder("buttons")
//junkdrawer.restoreListOrder("twolists1")
//junkdrawer.restoreListOrder("twolists2")

dragsort.makeListSortable(document.getElementById("numeric"),
verticalOnly, saveOrder)

dragsort.makeListSortable(document.getElementById("phonetic1"),
verticalOnly, saveOrder)
dragsort.makeListSortable(document.getElementById("phonetic2"),
verticalOnly, saveOrder)
dragsort.makeListSortable(document.getElementById("phonetic3"),
verticalOnly, saveOrder)
dragsort.makeListSortable(document.getElementById("phoneticlong"),
verticalOnly, saveOrder)

dragsort.makeListSortable(document.getElementById("boxes"),
saveOrder)

dragsort.makeListSortable(document.getElementById("buttons"),
saveOrder)

/*
dragsort.makeListSortable(document.getElementById("twolists1"),
saveOrder)
dragsort.makeListSortable(document.getElementById("twolists2"),
saveOrder)
*/
}

function verticalOnly(item) {
item.toolManDragGroup.verticalOnly()
}

function speak(id, what) {
var element = document.getElementById(id);
element.innerHTML = 'Clicked ' + what;
}

function saveOrder(item) {
var group = item.toolManDragGroup
var list = group.element.parentNode
var id = list.getAttribute("id")
if (id == null) return
group.register('dragend', function() {
ToolMan.cookies().set("list-" + id,
junkdrawer.serializeList(list), 365)
})
}
-->
</script>


<h2>Welcome <?=$username?> </h2>
<p><a href="newdebt.php">Add New</a></p>


<?php
if ( $_POST['original'] !='' ) {
//connect to database
$con mysql_connect("localhost","root","");
if (!
$con)
  {
  die(
'FIRE DA MISSALS: <br>' mysql_error());
  }
$original $_POST['original'];
$owedto $_POST['owedto'];
$notes $_POST['reason'];
$thetime time();

mysql_select_db("broke"$con);

$sql="INSERT INTO debts (user_id, original, current, owedto, notes, timestamp) VALUES ('$userId','$original','$original','$owedto','$notes', CURDATE() )";

if (!
mysql_query($sql,$con))
  {
  die(
'Error: ' mysql_error());
  }
echo 
"1 Less Paper to Worry about!";
mysql_close($con);
}
?>


<p> Current </p>

<?php
$con 
mysql_connect("localhost","root","");
mysql_select_db("broke"$con);
$query "SELECT current , owedto FROM debts WHERE user_id='$userId'";
$result mysql_query($query) or die(mysql_error());

echo 
"<ul id='boxes'>";
for(
$i 0$i mysql_num_fields($result); $i++){
  echo 
'<li class="box">'.mysql_field_name($result$i).'</li>';
}

while(
$row mysql_fetch_array($result)){
for($i 0$i mysql_num_fields($result); $i++){
echo '<li class="box">'$row[$i] ."</li>";
}
}

echo 
"</ul>";

?>



When I view this page say localhost/script/index.php the php and everything works fine except for the Java script. I cant drag and drop the list. The javascript works fine when its not in a php document.

Which makes me think it has something to do with the php/java interaction.
Logged
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 1598



View Profile
« Reply #1 on: January 13, 2010, 07:14:59 AM »

There is no PHP/java interaction.

Not sure why it's not working, but I would first try sticking that all into an external .js file, and removing all that inline HTML. Make PHP files contain PHP; It's very confusing otherwise. That HTML isn't just getting read by Apache, it's getting preprocessed by PHP.
Logged

Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!