Hello, here's my problem. I am building an administration page that displays the users where you can edit or delete them. This page is built using jquery's $.Post ajax function and I am trying to nun jquery inside the page that is called by $.post but it doesn't work at all.I was trying to hide a table and make the rows alternate colors .In the script below you can see that I assigned a function to the button "Edit users" to hide the table with id "even" This is only to check and see if it works but it doesn't.

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>display_users</title>
<script type="text/javascript" src="jquery.js"></script>

<script type = "text/javascript">
function(hideme){
$('#even').hide();  

};

</script>


</head>

<body>

<?php
include "../php_scripts/connection.php";

mysql_select_db($database)or die(mysql_error());
$field = $_REQUEST['field'];
$query = "SELECT * FROM users ";

if ($field == "newest_first")
{$query .="ORDER BY id ASC ";}


if ($field == "oldest_first")
{$query .="ORDER BY id DESC ";}


if ($field == "alphabetically")
{$query .="ORDER BY username ASC ";}


$query = mysql_query($query);

while ($row = mysql_fetch_assoc($query))
{
echo"<table id = 'admin_results'>";
    echo "
<tr>
<td width='50px'>ID</td>
<td width='200px'>Username</td>
<td width='200px'>Password</td>
<td width='200px'>E-mail</td>
<td width='75px'>Edit</td>
<td width='75p'>Delete</td>
</tr>
";

echo "<tr>";
echo "<td width='50px'>".$row['id']."</td>";
echo "<td width='200px'>".$row['username']."</td>";
echo "<td width='200px'>".$row['password']."</td>";
echo "<td width='200px'>".$row['email']."</td>";
echo "<td width='75px'> <input type ='button' name = 'edit_user' value = 'edit user' onclick = 'hideme();'/></td>";
echo "<td width='75px'> <input type ='button' name = 'delete_user' value = 'delete user'/></td>";
echo "</tr>";
echo "</table>";
echo "<table id='even'><tr><td></td></tr></table>";
}

?>
</body>
</html>

Recommended Answers

All 5 Replies

I've also tried to just assign a .

$(document).ready(function() {
 $('#edit_user').click(function() {
    $('#even').hide();
});   
});

click function to the button and it still won't work

Member Avatar for stbuchok

in your first post, function(hideme)... is wrong. It should be:

function hideme(){...}

in your second post, your are using a jQuery selector against id (#), however your input button does not have an id, it has a name.

add the id.

I appreciate the answer, I've changed it to id and still cant get it to work.

Member Avatar for stbuchok

Can you show your code with your changes again please?

I figured it out I'm using the "live" function it works, but I'm still having a hell of a time styling the results. I'm using the id of the row in the database to make an id for the respective button of the result as you see, so I can extract the id's of every button. I want to make a div below that slides down each result when you push the button to give you details about the user if you want to edit or delete it. But man.. it won't run. On a regular page it wouldn't be a problem but since this page is loaded with ajax it won't even show in the main page source.On top you can see that I'm selecting any button that is clicked to display it's id but it gives me an "undifined" result even though the button has an id .

<title>display_users</title>


<script type="text/javascript">
 $(":button").live("click", function()
 {alert($(this).id);
  }); 
</script>


</head>

<body>

<?php
include "../php_scripts/connection.php";

mysql_select_db($database)or die(mysql_error());
$field = $_REQUEST['field'];
$query = "SELECT * FROM users ";

if ($field == "newest_first")
{$query .="ORDER BY id ASC ";}


if ($field == "oldest_first")
{$query .="ORDER BY id DESC ";}


if ($field == "alphabetically")
{$query .="ORDER BY username ASC ";}


$query = mysql_query($query);

while ($row = mysql_fetch_assoc($query))
{


echo "<span>";   
echo"<table id = 'admin_results'>";
    echo "
<tr>
<td width='50px'>ID</td>
<td width='200px'>Username</td>
<td width='200px'>Password</td>
<td width='200px'>E-mail</td>
<td width='75px'>Edit</td>
<td width='75p'>Delete</td>
</tr>
";

echo "<tr>";
echo "<td width='50px'>".$row['id']."</td>";
echo "<td width='200px'>".$row['username']."</td>";
echo "<td width='200px'>".$row['password']."</td>";
echo "<td width='200px'>".$row['email']."</td>";
echo "<td width='75px'> <input type ='button' id = "."'id".$row['id']."'"." 'name = 'edit_user' value = 'edit user'/></td>";
echo "<td width='75px'> <input type ='button' name = 'delete_user' value = 'delete user'/></td>";
echo "</tr>";
echo "</table>";
echo "</span>";
echo "<div id='even'></div>"; 
}

?>


</body>
</html>
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.