Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OnClick Button

Status
Not open for further replies.

lexer

Programmer
Jun 13, 2006
432
VE
Hi

I've got a Dynamic Table from Mysql, the table has two columns "number" and "name", I want to add an onclick button (Return to home) at the end of the table, I put the onclick button at the end of the php code but the button appears at the top of the page, this my code:
Code:
<script type="text/JavaScript">
<!--
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->
</script>
<?php
//Mysql Conne.
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
//Select DB
mysql_select_db("calls", $con);
//Query
$query1 = "SELECT *".
"FROM numberlist ".
"ORDER BY name ";
$result1 = mysql_query($query1) or die(mysql_error());

/* Show Table */  
echo "<table border=1 cellpadding=4 cellspacing=0>";

/*Heading*/
 echo "<tr>
         <th colspan=2> Number List</th>
       <tr>
       <tr>
         <th> Number </th><th> Name</th>";

while($row1 = mysql_fetch_array($result1))
	{
	   echo "<tr>
	   <td> $row1[number] </td>
	   <td> $row1[name] </td>
	   </tr>";
	 }

?>
 <input name="Submit" type="submit" onclick="MM_goToURL('parent','index.php');return document.MM_returnValue" value="Home" />

Any ideas?

Thanks!!!


 
That's because you are putting the button code inside the table declaration. Move it past the closing </table> tag and it should end up at the bottom of the table.

Code:
[gray]
/* Show Table */  
echo "<table border=1 cellpadding=4 cellspacing=0>";

/*Heading*/
 echo "<tr>
         <th colspan=2> Number List</th>
       <tr>
       <tr>
         <th> Number </th><th> Name</th>";

while($row1 = mysql_fetch_array($result1))
    {
       echo "<tr>
       <td> $row1[number] </td>
       <td> $row1[name] </td>
       </tr>";
     }

?>
[/gray]
[blue]</table>[/blue]
[red]button code here[/red]




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks vacunita, It works!!!
Can I include the onclick button at the end of the dynamic table (put the onclick button in last row of the table)

 
sure, just stick it inside the cell you want it to go in.

Code:
[gray]<tr><td>[/gray][blue]button[/blue][gray]</td></tr>[/gray]


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks vacunita,
between <tr><td>Here</td></tr> Do I have to put the code for the button?:
Code:
<tr><td><input name="Submit" type="submit" onclick="MM_goToURL('parent','index.php');return document.MM_returnValue" value="Home" /></td></tr>
 
Exactly yes.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top