hi i have a jquery table populate from datebase:
<?php
$attributes = array('name' => 'users');
echo form_open('users/action',$attributes);?>
<table class="data display datatable" id="example">
<thead>
<tr>
<th>Username</th>
<th>Name</th>
<th>Nickname</th>
<th>Birthday</th>
<th>Sex</th>
<th>Address</th>
<th><input type="checkbox" id="select all"></th>
</tr>
</thead>
<tbody>
<?php foreach($query->result_array() as $row): ?>
<tr class="even gradeC">
<td><?php echo anchor('users/details/'.$row['usrID'],$row['usrName']);?></td>
<td><?php echo $row['usrpFirstName'].' '.$row['usrpLastName'];?></td>
<td><?php echo $row['usrpNick'];?></td>
<td><?php echo $row['usrpBday'];?></td>
<td><?php echo $row['usrpSex'];?></td>
<td><?php echo $row['usrpAddress'];?></td>
<td><input type="checkbox" name="checkID[]" id="checkID" value="<?php echo $row['usrID'];?>" />
<label for="checkID"></label></td>
</tr>
<? endforeach; ?>
</tbody>
</table>
<input type="submit" name="Delete" id="Delete" value="Delete" class="btn btn-orange" />
<input type="submit" name="Edit" id="Edit" value="Edit" class="btn btn-orange" onclick="return validateForm()" />
<input type="submit" name="AddUser" id="Add User" value="Add User" class="btn btn-orange" />
</form>
as you can see below,, i use checkID[] so that i can get every id of each user.
i did make a onlick on edit button so that it will check if the id is empty or not. heres my js function
<head>
<script type="text/javascript">
function validateForm()
{
var x=document.forms["users"]["checkID[]"].value
if (x==null || x=="")
{
alert("Please select user to edit.");
return false;
}
}
</script>
</head>
the problem now is that it will still alert even i check one user in the table..
even i use this:
<?php
$attributes = array('name' => 'users' , 'onsubmit' =>"return validateForm()");
echo form_open('users/action',$attributes);?>