Reputation: 103
I want to get content of my dt s an set them as value attr of input. this is my code.
//Html/php inline
$c=1;
while($user=mysqli_fetch_array($usersQryResult)){
echo"
<tr>
<td>$c</td>
<td>$user[user]</td>
<td>$user[pass]</td>
<td>$user[email]</td>
<td>$user[level]</td>
<td>$user[status]</td>
<td>$user[lastlogin]</td>
<td><i onclick=\"editUser($user[id],this)\" class='fa fa-pencil-square-o' title='edit user info'></i></td>
<td><i onclick=\"deleteUser($user[id],this)\" class='fa fa-trash-o deletUser' title='remove user' ></i></td>
</tr>
";
$c++;
//js/jquery
function editUser(id,thisObj){
var contents=$(thisObj).parent().siblings().text();
$("#chUserName").val(contents[1]);
$("#chUserPass").val(contents[2]);
$("#chUserEmail").val(contents[5]);
}
but contens[1]
,contents[2]
,content[3]
return 3 characters of my userName: for example: "Hamid" . will return H a m !!!?/
Upvotes: 0
Views: 1355
Reputation: 254
I will recomend that you assing a class to each <td>
that way you can reffer to each <td>
directly within the context of the parent. Something like this:
<td class="user">$user[user]</td>
<td class="password">$user[pass]</td>
<td class="email">$user[email]</td>
<td class="level">$user[level]</td>
<td class="status">$user[status]</td>
And then, your JS could be something like this:
function editUser(id,thisObj){
var context=$(thisObj).patent().parent();
$("#chUserName").val($(".user",context).text());
$("#chUserPass").val($(".password",context).text());
$("#chUserEmail").val($(".email",context).text());
Upvotes: 1