error : My is undefined in template
Im trying to make my table editable but i keep getting the following error:My is undefined
Thanks for all the help
Here is my code:
Thanks for all the help
Here is my code:
<html>
<head>
<title>Hardware Requests :: PHP Example</title>
<style> body, html {margin:0px; padding: 0px; overflow: hidden;font: menu;border: none;} </style>
<!-- ActiveWidgets stylesheet and scripts -->
<link href="./runtime/styles/xp/grid.css" rel="stylesheet" type="text/css" ></link>
<script src="./runtime/lib/grid.js"></script>
<script src='edit.js'></script>
<!-- ActiveWidgets PHP functions -->
<?php include("activewidgets.php") ?>
<!-- grid format -->
</script>
<style>
.active-templates-input {
overflow: hidden;
width: 100%;
height: 100%;
padding: 0px 5px;
margin: -1px 0px;
border: 1px solid #666;
vertical-align: middle;
font: menu;
line-height: 1.4em;
}
.active-templates-input.gecko {
display: block;
margin: 0px;
}
</style>
<script>
if (!window.My) My=[];
if (!My.Templates) My.Templates=[];
My.Templates.Input = Active.Templates.Text.subclass();
My.Templates.Input.create = function()
{
var obj = this.prototype;
// editor is not part of the template,
// there is only one single instance of editor object.
var editor = new Active.HTML.INPUT;
editor.setClass("templates", "input");
editor.setAttribute("type", "text");
editor.setAttribute("value", function(){
return template.getItemProperty("text");
});
// template variable provides temporary reference
// to the parent template during edit mode.
var template;
function switchToEditMode(){
if (template) {
switchToTextMode()
}
template = this;
template.element().style.padding = 0;
template.element().innerHTML = editor;
editor.element().focus();
}
obj.setEvent("ondblclick", switchToEditMode);
function switchToTextMode(){
var value = editor.element().value;
var originalVal = template.getItemProperty("text");
if(originalVal != value){
template.setItemProperty("text", value);
}
template.refresh();
template = null;
}
editor.setEvent("onblur", switchToTextMode);
};
My.Templates.Input.create();
var myData = new array();
<?php
include 'dbconnect.php';
$arrayname = myData;
$name1 = $_POST['mynames'];
//grid object name
$name = "obj";
// SQL query
$query = "Select `Hostname` , `Spec` , Booked_By , `Project` , `Subproject` ,`Proj_Mgr`, `Dept_Mgr`, `Purpose`, `Comments`, `TestSite_Type` from `tp` where `Dept_Mgr` = '$name1'" ;
// database connection
$resultset1 = new DB();
$resultset1->DB1();
if (!$resultset1) {
die('Invalid query: ' . mysql_error());
}
//query results
$data = $resultset1->query($query);
while ( $row = mysql_fetch_array($data) )
{
echo "myData.push[".$row['Hostname']."]";
echo "myData.push[".$row['Spec']."]";
echo "myData.push[".$row[' Booked_By ']."]";
echo "myData.push[".$row['Project']."]";
echo "myData.push[".$row['Subproject']."]";
echo "myData.push[".$row['Proj_Mgr']."]";
echo "myData.push[".$row['Dept_Mgr']."]";
echo "myData.push[".$row['Purpose']."]";
echo " myData.push[".$row['Comments']."]";
echo " myData.push[".$row['TestSite_Type']."]";
}
?>
var myColumns = [ "Hostname", "Spec", "Booked_By", "Project", "Subproject" , "Proj_Mgr" , "Dept_Mgr" , "Purpose" ,"Comms" , "TestSite_Type" ];
</script>
</head>
<body>
<script> // create ActiveWidgets Grid javascript object
var obj = new Active.Controls.Grid;
// set number of rows/columns
obj.setRowCount(20);
obj.setColumnCount(5);
// provide cells and headers text
// create editable text template
var templ = new My.Templates.Input;
// assign new template to all columns
obj.setColumnTemplate(templ);
// provide methods for getting and setting data
obj.getDataText = function(i, j){return myData[i][j]};
obj.setDataText = function(value, i, j){myData[i][j] = value};
obj.setColumnText(function(i){return myColumns[i]});
// disable arrow key nevigation
obj.setEvent("onkeydown", null);
// make input box selectable
obj.getTemplate("top").setEvent("onselectstart", obj.getEvent("onselectstart"));
obj.setEvent("onselectstart", null);
// set click action handler
//obj.setAction("click", function(src){window.status = src.getProperty("item/text")});
// write grid html to the page
document.write(obj);
</script>
</body>
</html>
redchord
August 23,