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);?>
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);?>
Share
Improve this question
edited May 26, 2011 at 5:27
kester martinez
asked May 26, 2011 at 5:13
kester martinezkester martinez
4316 gold badges14 silver badges24 bronze badges
1 Answer
Reset to default 3document.forms["users"]["checkID[]"]
will give you an array of all the checkboxes with that name. You're asking for the value
of the array which doesn't make sense. You'll need to loop through them to find out if any are checked with something like this:
function validateForm() {
var checkboxes = document.forms["users"]["checkID[]"];
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].checked) {
return true;
}
}
alert("Please select a user to edit.");
return false;
}
I haven't tested it but that code should give you the general idea.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744781228a4593352.html
评论列表(0条)