0
<!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>");
			
        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;
		while ($row = mysql_fetch_assoc($query)){ 
		
        echo("<TR 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>");  
}	  
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>

my question is how can i get the value of my button and display its value
button have a row so when button is clicked it should be determine whats row was clicked
and display it's sr_num my code above can anyone tell me how to get value of clicked button equal to the row

2
Contributors
10
Replies
11
Views
6 Years
Discussion Span
Last Post by yamot47
0
<!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','$i')></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>

( please find highlighted lines for modified code.)

you just give id to your table rows then,
in your java script you can know which row is clicked like this:

function buttonPress(str,x)
{
    var table = document.getElementById('test');   
    var rows=table.getElementsByTagName("tr");   
    for(var i=0;i<rows.length;i++)
    {
        ck=rows[i].id; 
        if(x==ck)
        alert("Row clcincked:"+ck); 

    }
}

Edited by mike_2000_17: Fixed formatting

0

start quote:

<!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','$i')></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>

(please find highlighted lines for modified code.)

you just give id to your table rows then,
in your java script you can know which row is clicked like this:

function buttonPress(str,x)
{
    var table = document.getElementById('test');   
    var rows=table.getElementsByTagName("tr");   
    for(var i=0;i<rows.length;i++)
    {
        ck=rows[i].id; 
        if(x==ck)
        alert("Row clcincked:"+ck); 

    }
}

end quote.

the code sir is now working can you tell me why?? and thanks for the reply in my thread

Edited by mike_2000_17: Fixed formatting

0

the code sir is now working can you tell me why?? and thanks for the reply in my thread

i just make an id for each row, gave name for the table,
then java script we can get all rows and ids from tha table name.
that's it.
Please mark this thread solved.

0

i just make an id for each row, gave name for the table,
then java script we can get all rows and ids from tha table name.
that's it.
Please mark this thread solved.

i dont get ur idea sir

0

my idea is when i cliked the button the value of button will display to another table but will not change page

0

what exactly you want?
if you want to simply display the clicked button value in another table,
then assign the

function buttonPress(str,x)
{
	var table = document.getElementById('test');   
	var rows=table.getElementsByTagName("tr");   
	for(var i=0;i<rows.length;i++)
	{
		ck=rows[i].id; 
		if(x==ck)
		//alert("Row clcincked:"+ck); 
                // assign it ck to table
		
	}
}

search for google for assigning into table.
or else post your code here, we will assist you.

0

what exactly you want?
if you want to simply display the clicked button value in another table,
then assign the

function buttonPress(str,x)
{
	var table = document.getElementById('test');   
	var rows=table.getElementsByTagName("tr");   
	for(var i=0;i<rows.length;i++)
	{
		ck=rows[i].id; 
		if(x==ck)
		//alert("Row clcincked:"+ck); 
                // assign it ck to table
		
	}
}

search for google for assigning into table.
or else post your code here, we will assist you.

i mean when i clicked the button it display it's value of the row i tried your code but the alert msg wont pop-up can you modify the code correct

0

i am giving you a small example, please go through this:

<table id="test" border=2>
<tr><td>SNO</td>
<td>Action</td></tr>
<?php for($i=0;$i<10;$i++){?>
<tr id=<?php echo $i;?>>
<td><?php echo $i;?></td>
<td><input type=button name=button value=Click onclick="buttonPress('<?php echo $i;?>');"></td>
</tr>
<?php }?>
</table>
<script type="text/javascript">
function buttonPress(x)
{
	var table = document.getElementById('test');   
	var rows=table.getElementsByTagName("tr");   
	for(var i=0;i<rows.length;i++)
	{
		ck=rows[i].id; 
		if(x==ck)
		alert("Row clcicked: "+ck); 
		
	}
}
</script>

Edited by Shanti C: n/a

0

i am giving you a small example, please go through this:

<table id="test" border=2>
<tr><td>SNO</td>
<td>Action</td></tr>
<?php for($i=0;$i<10;$i++){?>
<tr id=<?php echo $i;?>>
<td><?php echo $i;?></td>
<td><input type=button name=button value=Click onclick="buttonPress('<?php echo $i;?>');"></td>
</tr>
<?php }?>
</table>
<script type="text/javascript">
function buttonPress(x)
{
	var table = document.getElementById('test');   
	var rows=table.getElementsByTagName("tr");   
	for(var i=0;i<rows.length;i++)
	{
		ck=rows[i].id; 
		if(x==ck)
		alert("Row clcicked: "+ck); 
		
	}
}
</script>

code is working i tried it thanks but i want to display the row in a table when i click the button it will get the value of a row like name of a person it will display the name in a table the js will pass value to php im trying many code but i can do it
and thanks for your reply

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.