masterjiraya -3 Junior Poster

body.php

<html>
<head>
<script type="text/javascript">
function showUser(str, query)
{
if(document.getElementById("Author").checked==true)
{
    query="author";
}else if(document.getElementById("bookname").checked==true)
{
    query="bookname";
}else{
    document.getElementById("textHint")="please select";
}

if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","postback.php?q="+str+"&query_type="+query,false);
//xmlhttp.open("POST","postback.php",false);
xmlhttp.send();
}
</script><title>
    Search Books
</title>
</head>
<body>
<form method ="GET" >
    <div style="background-color:Orange" align="left">
<h3>Welcome<label name="name"><?php /*require('validation.php');*/ echo $_GET['uname'].", ";
?></label>Want to search a book?</h3>
Search:<input type="text" name="users" onKeyUp="showUser(this.value)"/><br/>
Search By<br/>
Author<input type="radio" name="query_type" id="Author" onClick="showUser()" checked="checked" style="color: Black"/>or by<input type="radio" name="query_type" id="bookname" onClick="showUser()"/>book name
    </div>
    </form>
<br />
<div id="txtHint" align="left"><b>Person info will be listed here.</b></div>

</body>
</html>

postback.php

<html><head><script type="text/javascript">
    function checkedItems(){
        
    }
</script></head>
    <body><?php
$q=$_GET['q'];
//$q=$_POST['str'];
$query_type=$_GET['query_type'];
//$query_type=$_POST['query'];

$words=explode(' ',$q);
$con = mysql_connect('localhost', 'root', 'naruto')or  die('Could not connect: ' . mysql_error());
mysql_select_db("clc_books", $con)or die('cannot connect');
$q = preg_replace('/\s\s+/', ' ', $q); // remove extra space
echo "<table border='1'>";
echo"
<tr>
<th>add to cart</th>
<th>book id</th>
<th>book name</th>
<th>Author</th>
<th>SRP</th>
</tr>";
$operator="";
$condition="";
for( $i = 0; $i < count($words); ++$i ){
	$condition.=$operator." CONCAT(".$query_type.") LIKE  CONVERT(_utf8 '%".$words[$i]."%' USING latin1) COLLATE latin1_swedish_ci";
	$operator=" OR ";
}
$sql = "SELECT *,CONCAT(".$query_type.") as fullname FROM `clc_books_list`   ";
if ($condition!="")
$sql .= " where ($condition) ";
$result = mysql_query($sql) or die('cannot query '.mysql_error($result));
$found=false;
while($row = mysql_fetch_array($result))
  {
 $found=true;
  echo "<tr>";
  echo "<td bgcolor='#ffff80'><input type='checkbox' id='checkboxChecked' name='" . $row['book_id'] . "'></td>";
  echo "<td bgcolor='#80ffff'>" . $row['book_number'] . "</td>";
  echo "<td bgcolor='#ff8c8c'>" . $row['bookname'] . "</td>";
  echo "<td  bgcolor='#ff8040'>" . $row['Author'] . "</td>";
  echo "<td  bgcolor='#ff7000'>" . $row['SRP'] . "</td>";
  echo "</tr>";
  }
if(!$found){
echo "<tr align='center'><td colspan=5 bgcolor='yellow'><b>NO<b> similar names with <font color=red><b>"./*$words[$wordCount2]*/$q.'</b></font></td></tr>';
  }
echo "</table>";
mysql_close($con);
?></body></html>

as you can see there was

while($row = mysql_fetch_array($result))
  {
 $found=true;
  echo "<tr>";
  echo "<td bgcolor='#ffff80'><input type='checkbox' id='checkboxChecked' name='" . $row['book_id'] . "'></td>";
  echo "<td bgcolor='#80ffff'>" . $row['book_number'] . "</td>";
  echo "<td bgcolor='#ff8c8c'>" . $row['bookname'] . "</td>";
  echo "<td  bgcolor='#ff8040'>" . $row['Author'] . "</td>";
  echo "<td  bgcolor='#ff7000'>" . $row['SRP'] . "</td>";
  echo "</tr>";
  }

it states here that the name of the list of array of checkboxes was taken from the database.

I want to know on how to get the value of the checkboxes when onchange attribute for Ajax is there. please kindly help me construct the code for the dynamic XML of checkboxes where these checkboxes were taken from the value in the database.

here's what I want to have as an output.

the checkboxes once it has been checked will automatically release it's value on the same page bcoz this is dynamic.

example I search the name of the author named Jim... all the Jim authors in the database of the coulmn of authors will released automatic with out click events.

besides that there was a checkbox that is not required to be checked unless you want to check it. let's assume you want an item from the list of books that was been released by the search query. you checked an item there or checked some items there. now what I want to have now is release all the values on the same DIV where the table releases

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.