does it's possible to retrieve data from a javascript ?? coz js is a client side script and php is a server side how can i get value of my js??

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
function buttonPress(str)
{
	var str;
alert(str);

}
</script>
</head>
<?php  session_start();
		error_reporting(E_ALL ^ E_NOTICE);
      include "dbconfig.php";
	 $id=$_SESSION["valid_user"];
 ?>
<body>
<form name="Item Search" method="post" action="search.php"> 
  Item Search:<br> 
  <label> 
  <input name="swords" type="text" size="30" maxlength="30"> 
  </label>  
  <br> 
  <label> 
  <input name="search" type="submit" id="search" value="Search"> 
  </label>
  <a href="logout.php">Logout</a> 
</form> 
 <?php
if (!$_POST['search']){ 
//determining the number of lenght of words

}else{ 
$searchwords = addslashes(htmlspecialchars($_POST['swords'])); 
if (strlen($searchwords) < 2){ 
echo "Your search must contain at least 3 characters. Please try again.<br><input type=button value='Back' onClick='history.go(-1)'>"; 
}else{ 
$words = explode(' ',$searchwords); 
$totalwords = count($words); 
$i = 0; 
$searchstring = ""; 
while ($i != $totalwords){ 
if ($i != 0 and $i != $wordcount){ 
$searchstring .= " and ";; 
} 
$searchstring .= "b_name LIKE '%$words[$i]%'"; 
$searchstring1 .= "b_author LIKE '%$words[$i]%'";
$i = $i + 1; 
} 
$starrow=10;
//getting query
$query = mysql_query("SELECT DISTINCT * FROM book where $searchstring or $searchstring1 LIMIT $starrow"); 
if (mysql_num_rows($query) == 0){ 
echo "No results were found.<br><input type=button value='Back' onClick='history.go(-1)'>"; 
}else{ 

		echo("<FORM METHOD=post id=form3>");
		echo("<H4 ALIGN=left>Books found matching search criteria :</H4><BR>");

		echo("</TABLE>");	
		//code in displaying the table 
        echo("<TABLE width='70%' border='2' cellpadding='3' ALIGN=CENTER   name='test' >");
			
        echo("<TR bgcolor='B0C4DE'>"); 
        echo("<TH>Sr.No</TH>");
        echo("<TH>Title Of Book</TH>");
        echo("<TH>Author Name</TH>");
        echo("<TH>Number of Copies</TH>");
		echo("<TH>Borrow</TH>");
		echo("</TR>"); 
	
	//searching using title of book
	$count=0;  $i=1; 		while ($row = mysql_fetch_assoc($query)){ 
		
        echo("<TR   id='$i'  bgcolor='B0C4DE'>"); 
	    $sr_num=$row['b_sr_num'];
		echo ("<td><input name=data id=data type=text id=data readonly=readonly  value=$sr_num></td>");
		echo ('<td>'.$row['b_name'].'</td>');
		echo ('<td>'.$row['b_author'].'</td>');
		echo ('<td>'.$row['b_avail'].'</td>');
	
		if($row['b_avail']>0)
		{
				if (!$_SESSION["valid_user"])
        {
        // User not logged in, redirect to login page
		echo("<td>Available</td>");
		}else
echo("<td><INPUT TYPE=button  id=show  name=show value=add onClick= buttonPress('$sr_num')></td>");
	
		}else
		echo("<td>No stock of book</td>");
		echo("</TR>"); 
		  $i=$i+1;  }	  
echo("</TABLE>"); 
		
		
		echo("<DIV ALIGN=CENTER><INPUT TYPE=SUBMIT NAME=Next VALUE=Next>");
	    echo("<INPUT TYPE=SUBMIT NAME=Previous VALUE=Previous></DIV>");
		echo("</FORM>");
	
} 
} 
}
  
?>
<form>

<div align="right">
  <table width="200" border="1">
    <tr>
      <td colspan="2"><center>Reserve Books</center></td>
      </tr>
    <tr>
      <td width="92"><?php echo '<script type="text/javascript"> buttonPress(str)</script>'; ?></td>
      <td width="92">&nbsp;</td>
      </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      </tr>
  </table>
</div>
</form>
</body>

</html>

The simplest way is to have a link to the PHP module with your javascript variable as the parm.

<a href=myphp.php?parm=[I]your_js_var[/I] ...  >

Also using AJAX you can retrieve the javascript variables to php.

Well when you page loads, first all the server side code is loaded then the client side code. So if you want the value of a javascript variable to be used in PHP...you'll have to send that value via a HTTPRequest or AJAX.

Feel free to search more on google regarding implementing this.

can you tell me any other way to get the value of a row when i click the button ?? coz i use js to test if the button is getting the value of it's row

Member Avatar for diafol

> can you tell me any other way to get the value of a row when i click the button ?? coz i use js to test if the button is getting the value of it's row

What??

can you tell me any other way to get the value of a row when i click the button ?? coz i use js to test if the button is getting the value of it's row

No...that cannot be done...you'll have to make a server call, either by refreshing the page, redirecting it or by making an asynchronous call using AJAX...

ah i want to refresh the page do you have any idea.. how to do it?

Use AJAX itself.It wil reload ur page/portion of a page

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.