Hi,
anyone can help me with getting the check box value?
this is my code.
Thank you
<HEAD>
<SCRIPT LANGUAGE="<strong class="highlight">JavaScript</strong>">
function getSelectedCheckbox(buttonGroup) {
// Go through all the check boxes. return an array of all the ones
// that are selected (their position numbers). if no boxes were checked,
// returned array will be empty (length will be zero)
var retArr = new Array();
var lastElement = 0;
if (buttonGroup[0]) { // if the button group is an array (one check box is not an array)
for (var i=0; i<buttonGroup.length; i++) {
if (buttonGroup[i].checked) {
retArr.length = lastElement;
retArr[lastElement] = i;
lastElement++;
}
}
} else { // There is only one check box (it's not an array)
if (buttonGroup.checked) { // if the one check box is checked
retArr.length = lastElement;
retArr[lastElement] = 0; // return zero as the only array value
}
}
return retArr;
} // Ends the "getSelectedCheckbox" function
function checkbox_checker() {
var checkBoxArr = getSelectedCheckbox(document.form1.chkid[$i]);
if (checkBoxArr.length == 0) { alert("No check boxes selected"); }
else {alert(getSelectedCheckboxValue(document.form1.chkid[$i]))}
}
</script>
</HEAD>
<p align="center"><strong><br>
THESE CASES MATCH YOUR QUERY. CLICK ON THE CASE NUMBER TO VIEW THE CASES.</strong></p>
<blockquote>
<p>
<FORM METHOD=POST ACTION="" name=form1 type="submit" >
<?php
$con = mysql_connect( "localhost", "root", "rootroot" ); //
$db = "x";
$TABLENAME = "lesson";
$primarykey = "lessonID";
mysql_select_db( $db );
// Get the search variable from URL
$query = "select * from $TABLENAME " ;
$result = mysql_query( $query, $con );
$fields = mysql_num_fields( $result );
for ( $i = 0; $i < $fields; $i++ )
{
$name = mysql_field_name( $result, $i );
// echo "$name = $row[$name]<BR>\n";
$field_names[] = $name;
if ( !empty( $_REQUEST["q"] ) )
$condition[] = sprintf( "`%s` like '%%%s%%'" , $name , mysql_real_escape_string( $_REQUEST["q"] ) );
// 'like' search condition to search in this field
}
echo "</br> Search word=".$_REQUEST["q"];
// i'm inserting this condition to the conditions array.
$query .= "WHERE verified='yes'" ;
if ( isset( $condition ) )
$query .= " AND " . implode( ' OR ', $condition );
// echo out the code generated..
$result_results = mysql_query( $query ) or die( mysql_error() );
$rows = mysql_num_rows($result_results);
echo "</br> Number of searched result=".$rows;
$query_with_max=$query.$max;
$results_with_max=mysql_query($query_with_max);
//echo "</br>".$query_with_max;
if ( mysql_num_rows( $results_with_max ) > 0 )
{
echo "<table border=\"1\">";
echo "<tr>";
echo "<th>Result NO</th>";
echo "<th>Select</th>";
$counter = 0;
foreach( $field_names AS $field_title )
{
echo "<th>" . ucwords( $field_title ) . "</th>";
if ( $counter >= 8 )
break;
$counter++;
}
echo "</tr>";
$i = 1;
while ( $rows_results = mysql_fetch_assoc( $results_with_max ) )
{
echo "<tr>";
echo "<td>$i.</td>";
echo "<td><input type=\"checkbox\" name=\"chkid[$i]\" ></td>";
$counter = 0;
foreach( $field_names AS $fn )
{
if ( $fn != $primarykey )
echo "<td>" . $rows_results[$fn] . "</td>";
else
echo '<td><a href="related.php?lessonID=' . $rows_results[$primarykey] . '">' . $rows_results[$primarykey] . '</a></td>';
if ( $counter >= 8 )
break;
$counter++;
}
// this cell holds then an URL to another page , and the primary key's value embedded into the url by a GET values...
$i++;
echo "<tr>";
}
echo "</table>";
}
else
echo "<br>No result in $TABLENAME table ...";
?>
<input type="submit" name="Submit" value="Submit" onClick="checkbox_checker()">
</form>
</p>
</blockquote>