...

View Full Version : multiple checkbox disable on submit



shahrukh1514
04-02-2010, 06:50 AM
Dear Coders,

I have a requirement where i need to disable selected checkboxes when i click on submit button.

eg: I have 10checkboxes and a submit button in a form. When i click any 4 or 5 checkboxes and press submit button then the values of the checkboxes should be stored in MySql table and the checkboxes should get disabled. Please elp me out in writing the codings.

Len Whistler
04-02-2010, 07:36 AM
MySQL database, two tables.

USER TABLE
id | email | ip_address |

001 |
002 |
003 |


CHECKBOX TABLE
id | user_id | checkbox | status
001 | 002 | 1 | 0
002 | 002 | 2 | 0
003 | 002 | 3 | 0
004 | 003 | 2 | 0

When user logs in do not display - or disable - checkboxes with a status of "0". That table is updated when ever the user submits the form.



-----------

shahrukh1514
04-02-2010, 07:59 AM
Dear Coders,

I have a requirement where i need to disable selected checkboxes when i click on submit button.

eg: I have 10checkboxes and a submit button in a form. When i click any 4 or 5 checkboxes and press submit button then the values of the checkboxes should be stored in MySql table and the checkboxes should get disabled. Please elp me out in writing the codings.


This is what i want to do....

I am doing project titled "Online Bus Reservation System" and i completed the admin part who can fill in the bus details from source to destination and here is the form which redirects the admin to details page

//admin.php
<?php
function save(){
include('connection.php');
go();
}
$y=2;
function show_form() {
global $HTTP_POST_VARS, $print_again, $error;
?>
<?php
}
if(isset($_POST["Submit"])) {
check_form();
}
function check_form()
{
global $HTTP_POST_VARS, $error, $print_again;
$error['mypassword'] = false;
$error['myusername'] = false;
if($_POST['mypassword']=="")// || (ereg("[^A-Za-z ]$", $_POST["fname"])))
{
$error['mypassword'] = true;
$print_again = true;
echo "The Password field is empty or invalid<br><br>";

}
if($_POST['myusername']=="")// || (ereg("[^A-Za-z ]$", $_POST["fname"])))
{
$error['username'] = true;
$print_again = true;

echo "The Username field is empty or invalid<br><br>";

}
if($print_again) {
show_form();
} else {
show_form();
save();
}
}
function go(){
$b1 = $_POST['myusername'];
$b2 = $_POST['mypassword'];
if($b1=='admin' && $b2=='1234')
{
mysql_query("insert into login values('1')");
header("location:bus.php");
}
else
{
mysql_query("insert into login values('0')");
$y=1;
}
if(@$y==1)
{
mysql_query("insert into login values('0')");
echo "Wrong Username or Password";
}
a:
}
?>
<html>
<head>
<title>
Attendance Section</title>
</head>

<body>
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Admin Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername" value=""></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="password" id="mypassword" value=""></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Login">
</tr>
</table>
</td>
</form>
</tr>
</table>
</body>
</html>

and after sucessful login the admin can fill the bus details in this form

//bus.php

<?php

$a=@$_POST['bno'];
$b=@$_POST['bsource'];
$c=@$_POST['bdest'];
$d=@$_POST['barr'];
$e=@$_POST['bdept'];
$f=@$_POST['chk1'];
$g=@$_POST['chk2'];
$h=@$_POST['chk3'];
$i=@$_POST['chk4'];
$j=@$_POST['chk5'];
$k=@$_POST['chk6'];
$l=@$_POST['chk7'];
$m=@$_POST['bfare'];
$n=@$_POST['chk'];
$sub=@$_POST['sub'];
//$n=$_POST['res'];
include('connection.php');
mysql_query("delete from login where id=0");
$sql=mysql_query("SELECT * FROM login order by id desc limit 1");
while($p=@mysql_fetch_array($sql))
{
$q=$p['id'];
}
// Mysql_num_row is counting table row
//$a=mysql_num_rows($result);
if($q==1)
{
session_start();

if($sub=="Add")
{
mysql_query("insert into bus (`no`, `source`, dest, arr, dep, mon, tue, wed, thu, fri, sat, sun, fare) VALUES ('$a','$b','$c','$d','$e','$f','$g','$h','$i','$j','$k','$l','$m')");
}
?>

<html>
<head>
<title>
Online Bus Reservation
</title>
</head>
<body>
<form method="post">
<table border="1">
<tr><td>BusNo </td><td><input type="text" size="25" name="bno" /></td></tr>
<tr><td>Source </td><td><input type="text" size="25" name="bsource" /></td></tr>
<tr><td>Destination </td><td><input type="text" size="25" name="bdest" /></td></tr>
<tr><td>Arrival Time </td><td><input type="text" size="25" name="barr" /></td></tr>
<tr><td>Depart Time </td><td><input type="text" size="25" name="bdept" /></td></tr>
<tr><td>Fare </td><td><input type="text" size="25" name="bfare" /></td></tr>
<tr><td colspan="2">
<input type="checkbox" value="y" name="chk1"/>Mo
<input type="checkbox" value="y" name="chk2"/>Tu
<input type="checkbox" value="y" name="chk3"/>We
<input type="checkbox" value="y" name="chk4"/>Th
<input type="checkbox" value="y" name="chk5"/>Fr
<input type="checkbox" value="y" name="chk6"/>Sa
<input type="checkbox" value="y" name="chk7"/>Su
</td></tr>
<td><input type="submit" name="sub" value="Add" /></td>
<br /><br />
<a href="logout.php">LogOut</a>
</table>
</form>
</body>
</html>
<?php }
else
{
header('location:admin.php');
}

?>


and here is the customers page where the customer sees the bus details to reserve a seat for a particular route to travel.


//cust.php

<html>
<head>
<title>
Online Bus Reservation
</title>
</head>
<body>
<form method="post" name="myForm">
<?php if(@$_GET['x']!=1){ ?>

<table border="1">
<tr><td>BusNo </td>
<td>Source </td>
<td>Destination </td>
<td>Arrival Time </td>
<td>Depart Time </td>
<td>Fare </td>
<td>Mon </td>
<td>Tue </td>
<td>Wed </td>
<td>Thu </td>
<td>Fri </td>
<td>Sat </td>
<td>Sun </td>
<td>Reservation </td></tr>

<?php
include('connection.php');
$riy=mysql_query("select * from bus");
while($a=@mysql_fetch_array($riy))
{
echo '<tr> <td>';
echo $a['no']; echo '</td>'; echo '<td>';
echo $a['source']; echo '</td>'; echo '<td>';
echo $a['dest']; echo '</td>'; echo '<td>';
echo $a['arr']; echo '</td>'; echo '<td>';
echo $a['dep']; echo '</td>'; echo '<td>';
echo $a['fare']; echo '</td>'; echo '<td>';
echo $a['mon']; echo '</td>'; echo '<td>';
echo $a['tue']; echo '</td>'; echo '<td>';
echo $a['wed']; echo '</td>'; echo '<td>';
echo $a['thu']; echo '</td>'; echo '<td>';
echo $a['fri']; echo '</td>'; echo '<td>';
echo $a['sat']; echo '</td>'; echo '<td>';
echo $a['sun']; echo '</td>'; echo '<td>';
echo "<a href='http://localhost/cust.php?x=1'>Reserve </a>";
echo '</td>';
}
}
if(@$_GET['x']==1)
{ ?>

</table>
<table><br />
<tr>
<td><input type="checkbox" name="res" value="1">Seat1 </td>
<td><input type="checkbox" name="res2" value="2">Seat2 </td>
<td><input type="checkbox" name="res3" value="3">Seat3 </td>
<td><input type="checkbox" name="res4" value="4">Seat4 </td>
<td><input type="checkbox" name="res5" value="5">Seat5 </td>
<td><input type="checkbox" name="res6" value="6">Seat6 </td>
<td><input type="checkbox" name="res7" value="7">Seat7 </td>
<td><input type="checkbox" name="res8" value="8">Seat8 </td>
<td><input type="checkbox" name="res9" value="9">Seat9 </td>
<td><input type="checkbox" name="res10" value="10">Seat10 </td></tr>
<input type="submit" name="sub" value="Reserve" onclick="check()"/>
</table>

<?php } ?>

</form>
<script type="text/javascript">
function check()
{
if(document.getElementByName('res').checked==true)
document.getElementByName('res').disabled=true;
}
</script>
</body>
</html>

Now in this page when the customer clicks Reserve button then the page is submitted to itself with x value as '1'. Now the other half of the page is shown where the seat numbers of the bus is shown from '1 to 10'. Now when the customer checks the seat number and clicks the Reserve button then the selected checkbox must be disabled so that he cannot click the same checkbox twice. And also the value of the selected checkboxes should be stored in the table.


I hope i explained everything to you all. Please help me out.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum