3.0.5

How to put value for each check box ????

I wanna know that How to put value for each check box .

Cause, I need to send value in check box to another page (I used PHP). Now my main page can put check box in grid . Plzzz Solve this problem


// My main page

<script>
if (!window.My) My=[];
if (!My.Templates) My.Templates=[];


// ****************************************************************
// Checkbox Cell Template.
// ****************************************************************

My.Templates.Checkbox = Active.System.Control.subclass();

My.Templates.Checkbox.create = function(){

var obj = this.prototype;

obj.defineModel("checked");
obj.defineCheckedProperty("true", "Y");
obj.defineCheckedProperty("false", "N");

obj.setClass("templates","checkbox");

var checkbox = new Active.HTML.INPUT;
checkbox.setClass("input","checkbox");
checkbox.setClass("checkbox", function(){return this.getColumnProperty("index")});
checkbox.setAttribute("type","checkbox");

<?php

include"config.inc.php";

$scode_tmp=$_SESSION['scode'];
$shipcode_tmp=$scode_tmp;


$dbconn = pg_connect("host=$hostname dbname=$dbname user=$usernamedb password=$passworddb")
or die('Could not connect: ' . pg_last_error());

$sql="select * from component where shipcode ='$shipcode_tmp'";
$result = pg_query($dbconn, $sql);
$rows = pg_num_rows($result);

for ($i=0;$i<100;$i++){

$array = pg_fetch_array ($result);
$itemcode=$array[itemcode];

//grid data

echo "checkbox.setAttribute(\"value\",\"$itemcode,\"); ";
}

// Free resultset
pg_free_result($result);

// Closing connection
pg_close($dbconn);

?>

checkbox.setAttribute("checked", function(){
return (this.getItemProperty("text") == this.getCheckedProperty("true"))
});

function toggleValue(){
var originalVal = this.getItemProperty("text");
var newValue = (originalVal == this.getCheckedProperty("true")) ? this.getCheckedProperty("false") : this.getCheckedProperty("true");
newValue = (originalVal == this.getCheckedProperty("true")) ? this.getCheckedProperty("false") : this.getCheckedProperty("true");
this.setItemProperty("text", newValue);
document.form1.test1.value=document.form1.elements.length;
document.form1.test2.value="";
for(a=2;a<document.form1.elements.length;a++){
if(document.form1.elements[a].checked==true){
document.form1.test2.value=document.form1.test2.value + document.form1.elements[a].value;
}
}
this.refresh();
}

checkbox.setEvent("onclick", toggleValue);

obj.setContent("checkbox", checkbox);

};

My.Templates.Checkbox.create();

// ****************************************************************
// CheckboxLabel Cell Template.
// ****************************************************************

/*My.Templates.CheckboxLabel = My.Templates.Checkbox.subclass();

My.Templates.CheckboxLabel.create = function(){

var obj = this.prototype;

var label = new Active.HTML.SPAN;
label.setClass("checkbox","text");
label.setContent("text", function() { return this.getItemProperty("text"); });

obj.setContent("text", label);
};

My.Templates.CheckboxLabel.create(); */

</script>
</head>

<body>

<?php

echo"<form name=\"form1\" method=\"post\" action=\"test_config.php?itemcode=$itemcode\">";
echo "<input type=\"text\" name=\"test1\" > <input type=\"text\" name=\"test2\" size=\"100\">";

//select data from DB
//include"config.inc.php";

//$scode_tmp=$_SESSION['scode'];
//$shipcode_tmp=$scode_tmp;


$dbconn = pg_connect("host=$hostname dbname=$dbname user=$usernamedb password=$passworddb")
or die('Could not connect: ' . pg_last_error());

$sql="select * from component where shipcode ='$shipcode_tmp'";
$result = pg_query($dbconn, $sql);
$rows = pg_num_rows($result);

echo"<script>";
echo" var myData = [";

for ($i=0;$i<100;$i++){

$array = pg_fetch_array ($result);
$itemcode=$array[itemcode];
$itemdesc=$array[itemdesc];
$qty=$array[qty];
$locode=$array[locode];
$statuscode=$array[statuscode];


//grid data

echo"[\"$itemcode\", \"$itemdesc\", \"$qty\", \"$locode\", \"$statuscode\",\"$itemcode \"], ";


}

echo"];";
echo" var myColumns = ["."\"ÃËÑÊÍØ»¡Ã³ì\", \"ÃÒÂÅÐàÍÕ´\", \"¨Ó¹Ç¹\", \" µÓá˹è§\", \"ʶҹÐ\",\"EDIT\" "."];";
echo"</script>";


// Free resultset
pg_free_result($result);

// Closing connection
pg_close($dbconn);


?>

<?php
echo"<font = \"Ms Sans Serif\" size =\"2\"><br>Configuration Status :<br><br></font>";

?>

<script>

// create ActiveWidgets Grid javascript object
var obj = new Active.Controls.Grid;


var chkTemplate = new My.Templates.Checkbox;
chkTemplate.setCheckedProperty("true", "Yes")
chkTemplate.setCheckedProperty("false", "No")
obj.setColumnTemplate(chkTemplate,5);

// set number of rows/columns
obj.setRowProperty("count", <? echo "$i"; ?>);
obj.setColumnProperty("count", 6);

// provide cells and headers text
obj.setDataProperty("text", function(i, j){return myData[i][j]});
obj.setColumnProperty("text", function(i){return myColumns[i]});


// set headers width/height
obj.setRowHeaderWidth("28px");
obj.setColumnHeaderHeight("20px");

// set click action handler
obj.setAction("click", function(src){window.status = src.getItemProperty("text")});




// write grid html to the page
document.write(obj);




</script>

<?php
echo"<input type=\"submit\" name=\"Submit\" value=\"Submit\">";
echo "</form>";
?>
</body>
</html>


Ocka
March 21,
I think "to get the value" you just need to add this line:

obj.setDataText = function(value, i, j){myData[i][j]=value}

to this block:

// provide cells and headers text
obj.setDataProperty("text", function(i, j){return myData[i][j]});
obj.setColumnProperty("text", function(i){return myColumns[i]});

HTH
Carlos
March 21,
Hi , Carlos

to this block:

//grid data
echo "checkbox.setAttribute(\"value\",\"$itemcode,\"); ";
}
// Free resultset
pg_free_result($result);

// Closing connection
pg_close($dbconn);

?>

checkbox.setAttribute("checked", function(){
return (this.getItemProperty("text") == this.getCheckedProperty("true"))
});

My main page only show the latest value of grid (all of check box)
I'm tried to solve them but when I click check box ,it's show same value. ???
Ocka
March 21,

This topic is archived.

See also:


Back to support forum