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:
<?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.