Sekiranya cuma ada 1 sahaja radio button, array tak jalan. Tak boleh nak check guna kaedah array. Jadi, pisahkan. Jika jumpa satu, check seperti biasa, jika lebih, baru buat checking guna array.
if(document.getElementsByName('namatbl').length == 1){ }else { }
Dalam isu ni, user mesti pilih satu radio button.
<html>
<head>
<title>Mi-Scramble</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function validatePwd() {
if(document.getElementsByName('namatbl').length == 1)
{
if(document.myForm.namatbl.checked)
{
return true;
} else {
alert ("You must select one table! ");
return false;
}
} else {
var flag = 0;
for (var i = 0; i< document.myForm.namatbl.length; i++) {
if(document.myForm.namatbl[i].checked){
flag++;
}
}
if (flag < 1) {
alert ("You must select one table! ");
return false;
}
return true;
}
}
</script>
</head>
<body>
<form action="assignuserselect.php" method="post" name=myForm onSubmit="return validatePwd();">
<table class="responsive table table-striped">
<tr>
<th>Server</th>
<th>Database</th>
<th>Table</th>
<th>Action</th>
</tr>
<?php
$sqlrtbl="SQL";
$resulrtbl=pg_query($sqlrtbl);
while($rowr = pg_fetch_assoc($resulrtbl))
{
?>
<tr>
<td><?php echo $rowr['server']; ?></td>
<td><?php echo $rowr['dbname']; ?></td>
<td><?php echo $rowr['dbtbl']; ?></td>
<td><input type="radio" name="namatbl" value="<?php echo $rowr['dbtbl']; ?>"></td>
</tr>
<?php
}
if(!$namatable)
{
?>
<tr>
<td colspan="4"><font color="red"><center>No scrambled table from you.</center></font></td>
</tr>
<?php
}
?>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td>
<?php if($namatable) { ?>
<input class="btn btn-primary" type="submit" value="Submit">
<?php } ?>
</td>
</tr>
</table>
</form>
</body>
</html>
Sourcecode for blogspot http://codeformatter.blogspot.com/
0 comments:
Post a Comment