onClick event
Hi all,
I want to be able to click on a row and throw up an alert box with the data contained in the highlighted row. How complicated of a task is this?
Thanks!
-Matt
September 10,
Here is the code:
obj.setAction("click", function(src){
var row = src.getRowProperty("index");
var count = this.getColumnProperty("count");
var column, result = [];
for (column = 0; column < count; column++){
result.push(this.getDataProperty("text", row, column));
}
alert(result);
});
Alex (ActiveWidgets)
September 11,
Thanks Alex. Much appreciated!
-Matt
September 13,
Data is truncated when it is larger than the width size. I would also like to click on a row and throw up an alert box to display the text in the row. How to incorprate the above code into my programs?
Currently, my code looks like the following:
function activewidgets_grid($name, &$data){
$row_count = @mysql_num_rows($data);
$column_count = @mysql_num_fields($data);
$columns = "var ".$name."_columns = [\n";
$columns .= "\"".""."\", ";
$columns .= "\""."Academic Preparation"."\", ";
$columns .= "\""."Date"."\", ";
$columns .= "\n];\n";
$rows = "var ".$name."_data = [\n";
while ($result = @mysql_fetch_array($data)) {
$rows .= "[";
for ($i=0; $i < $column_count; $i++) {
$rows .= "\"".activewidgets_html($result[$i])."\", ";
}
$rows .= "],\n";
}
$rows .= "];\n";
$html = "<"."script".">\n";
$html .= $columns;
$html .= $rows;
$html .= "try {\n";
$html .= " var $name = new Active.Controls.Grid;\n";
$html .= " $name.setRowCount($row_count);\n";
$html .= " $name.setColumnCount($column_count);\n";
$html .= " $name.setDataText(function(i, j){return ".$name."_data[i][j]});\n";
$html .= " $name.setColumnText(function(i){return ".$name."_columns[i]});\n";
$html .= " document.write($name);\n";
$html .= "}\n";
$html .= "catch (error){\n";
$html .= " document.write(error.description);\n";
$html .= "}\n";
$html .= "</"."script".">\n";
return $html;
}
function activewidgets_html($msg){
$msg = addslashes($msg);
$msg = str_replace("\n", "\\n", $msg);
$msg = str_replace("\r", "\\r", $msg);
$msg = htmlspecialchars($msg);
return $msg;
}
November 29,
i want to use the onclick event of select tag an get the value of the selected filed in the script ... plz help me
Hunny
August 27,
This code worked great but how can I pass the "result" array to a local or session variable?
The following is a small portion of my code that deals with the row select and popup alert. Instead of receiving an alert, I want to pass "result" to $copyRow or $_SESSION["gridRow"].
The commented lines are a couple things I've tried and failed.
I think it's a PHP/HTML issue rather than AW. Any help would be appreciated.
Regards,
$html .= " $name.setRowProperty(\"image\", function(i,j){return ".$name."_myImages[i]});\n";
$html .= " $name.setDataText(function(i,j){return ".$name."_data[i][j]});\n";
$html .= " $name.setAction(\"click\", function(src){\n";
$html .= " var row = src.getRowProperty(\"index\");\n";
$html .= " var count = this.getColumnProperty(\"count\");\n";
$html .= " var column, result = [];\n";
$html .= " for (column = 0; column < count; column++){\n";
//$html .= " $copyRow.push(this.getDataProperty(\"text\", row, column));\n";
$html .= " result.push(this.getDataProperty(\"text\", row, column));\n";
$html .= " }\n";
//$html .= " $copyRow = result;\n";
$html .= " alert(result);\n";
$html .= " });\n";
Avnish
March 1,