Jump to content

How to disappear a checkbos after it is checked


FinnKim

Recommended Posts

Hello every one :)

 

Before anything my english is so bad!

 

I am making a table for booking time, I have put times as checkboxs, and I wand that checkbox become unselectable or

disappears from the table after it is selected once. I tried to validate if data is found on database and then make it disappear, but it was not successful.

 

my table looks like this:

 

Sieppaa.jpg

 

 

Actually  date and time come from another table on database. This is my  php code for each check bos:

echo"
<input type='radio' name='datetime' value='". $row['day1']."   ".$row['time1']."'>
<p>". $row['day1'] ,"</p><br/>". $row['time1'] ."

 

 

can you please help me :-\

 

 

Link to comment
Share on other sites

You could use javascript or jquery to do this. The problem is, if you completely disable the checkbox it wont get sent in the post array. There are two options I can think of, setup a jQuery event for the click on the box, if it is already checked then just don't allow it to uncheck! Second would be to test in php if it was selected and simply hide it with css.

 

If you wish I can put together a small tutorial on my blog for you?

Link to comment
Share on other sites

If you wish I can put together a small tutorial on my blog for you?

 

The idea of this forum is not to help yourself generate traffic to your own site, but to share with the community here. If you think you can help, your welcome to post your solution right here.

Link to comment
Share on other sites

1. Those are radio buttons.

2. Do you want them to pick one from each row or one from each column, or one from all 16?

 

Yes those are radio buttons and from only form. I want pick only one and after that it becomes unselectable

or unavailable or disappears from form.

 

here bigger picture of form:

 

 

Sieppaa.jpg

 

 

Everything work good, exept for I don't know how to make this buttons unavailble after being selected?

 

Here is also my php code:

 


<?php
$con = mysql_connect("localhost", "root", "");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

$db_selected = mysql_select_db("college",$con);

if (!$db_selected)
  {
  die ("No Database: " . mysql_error());
  }

//mysql_close($con);
?>
<?php
$v_counselor=$_POST["counselor"];
$v_fname=$_POST['fname'];
$v_lname=$_POST['lname'];
$v_studentId=$_POST['studentId'];
$v_gender=$_POST["gender"];
$v_email=$_POST['email'];
$v_tel=$_POST['tel'];
$v_month=$_POST['month'];
$v_topic=$_POST['topic'];
$v_datetime=$_POST['datetime'];
$v_detail=$_POST["detail"];
//$v_gender= serialize($_POST["gender"]); 

// check for null values

if ($v_fname==""  or $v_lname==""or $v_email=="" or $v_tel=="")

echo "All fields must be entered correctly";

    
// validate a phone number
//elseif(!preg_match("#^[0-9]{8}$#",$v_tel))	
//echo 'Please enter a valid phone number';
elseif(!ctype_alpha($v_fname))
echo "Please correct your  FIRST NAME";

elseif(!ctype_alpha($v_lname))
echo "Please correct your LAST NAME";

elseif(ctype_alpha($v_tel))
echo "Phonenumber is not valid";



else{
//insert values into the table
$query="insert into students(counselor,fname,lname,studentId,email,tel,gender,topic,month,datetime,detail) 
values('$v_counselor','$v_fname','$v_lname','$v_studentId','$v_email','$v_tel','$v_gender','$v_topic','$v_month','$v_datetime','$v_detail')";

mysql_query($query)  or die(mysql_error());

echo "Registration was successful";
}

?>


 

 

and here is the form's  codes:

 

<form name="form1" method="post" action="login/insert.php">
<table width="500" border="0" cellspacing="1" cellpadding="3" bgcolor="#CCCCCC">
<tr>
<td >Counselor</td>
<th>:</th>
<td>
<select name="counselor">
<option></option>
<option value="con1">Counselor A</option>
<option value="con2">Counselor B</option>
</select> 
</td>
</tr>
<tr>
<td height="31">First name</td>
<td>:</td>
<td><input name="fname" type="text" id="fname" size="30"></td>
</tr>
<tr>
<td>Last name</td>
<th>:</th>
<td><input name="lname" type="text" id="lname" size="30"></td>
</tr>
<tr>
<td height="31">Student ID</td>
<th>:</th>
<td ><input name="studentId" type="text" id="studentId" size="30"></td>
</tr>
<tr>
<td height="31">Gender</td>
<th>:</th>
<td>
<select name="gender">
<option></option>
<option value="Male">Male</option>
<option value="Femle">Eemale</option>
</tr>
<tr>
<td>Email</td>
<th>:</th>
<td><input name="email" type="text" id="email" size="30"></td>
</tr>
<tr>
<td>Telephone</td>
<td>:</td>
<td><input name="tel" type="text" id="tel" size="30"></td>
</tr>
<tr>
<td>Topic</td>
<td>:</td>
<td><input name="topic" type="text" id="topic" size="30"></td>
</tr>
<tr>
<td>Date</td>
<td>:</td>
<td>

<div class=' contentcalendar'>

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("calendar", $con);

$result = mysql_query("SELECT * FROM datetime  ORDER BY id DESC LIMIT 1");

while($row = mysql_fetch_array($result))
  {

echo"<div class='month' align='center'><input type='hidden' name='month' value='".$row['month']."' ><l>".$row['month']."</l></div>";



echo"
<div  class='box'>
<div class='boxbut'>
<input type='radio' name='datetime' value='". $row['day1']."   ".$row['time1']."'>
<d>". $row['day1'] ,"</d><br/><t>". $row['time1'] ."</t>
</div>
</div>";



echo"
<div  class='box'>
<div class='boxbut'>
<input type='radio' name='datetime' value='". $row['day1']."   ".$row['time2']."'>
<d>". $row['day1'] ,"</d><br/><t>". $row['time2'] ."</t>
</div>
</div>";


echo"
<div  class='box'>
<div class='boxbut'>
<input type='radio' name='datetime' value='". $row['day1']." AT ".$row['time3']."'>
<d>". $row['day1'] ,"</d><br/><t>". $row['time3'] ."</t>
</div>
</div>";



echo"
<div  class='box'>
<div class='boxbut'>
<input type='radio' name='datetime' value='". $row['day1']."   ".$row['time4']."'>
<d>". $row['day1'] ,"</d><br/><t>". $row['time4'] ."</t>
</div>
</div>";




echo"
<div  class='box'>
<div class='boxbut'>
<input type='radio' name='datetime' value='". $row['day2']."   ".$row['time5']."'>
<d>". $row['day2'] ,"</d><br/><t>". $row['time5'] ."</t>
</div>
</div>";



echo"
<div  class='box'>
<div class='boxbut'>
<input type='radio' name='datetime' value='". $row['day2']."   ".$row['time6']."'>
<d>". $row['day2'] ,"</d><br/><t>". $row['time6'] ."</t>
</div>
</div>";


echo"
<div  class='box'>
<div class='boxbut'>
<input type='radio' name='datetime' value='". $row['day2']."   ".$row['time6']."'>
<d>". $row['day2'] ,"</d><br/><t>". $row['time7'] ."</t>
</div>
</div>";

echo"
<div  class='box'>
<div class='boxbut'>
<input type='radio' name='datetime' value='". $row['day2']."   ".$row['time8']."'>
<d>". $row['day2'] ,"</d><br/><t>". $row['time8'] ."</t>
</div>
</div>";


echo"
<div  class='box'>
<div class='boxbut'>
<input type='radio' name='datetime' value='". $row['day3']."   ".$row['time9']."'>
<d>". $row['day3'] ,"</d><br/><t>". $row['time9'] ."</t>
</div>
</div>";


echo"
<div  class='box'>
<div class='boxbut'>
<input type='radio' name='datetime' value='". $row['day3']."   ".$row['time10']."'>
<d>". $row['day3'] ,"</d><br/><t>". $row['time10'] ."</t>
</div>
</div>";


echo"
<div  class='box'>
<div class='boxbut'>
<input type='radio' name='datetime' value='". $row['day3']."   ".$row['time11']."'>
<d>". $row['day3'] ,"</d><br/><t>". $row['time11'] ."</t>
</div>
</div>";


echo"
<div  class='box'>
<div class='boxbut'>
<input type='radio' name='datetime' value='". $row['day3']."   ".$row['time12']."'>
<d>". $row['day3'] ,"</d><br/><t>". $row['time12'] ."</t>
</div>
</div>";


echo"
<div  class='box'>
<div class='boxbut'>
<input type='radio' name='datetime' value='". $row['day4']."   ".$row['time13']."'>
<d>". $row['day4'] ,"</d><br/><t>". $row['time13'] ."</t>
</div>
</div>";


echo"
<div  class='box'>
<div class='boxbut'>
<input type='radio' name='datetime' value='". $row['day4']."   ".$row['time14']."'>
<d>". $row['day4'] ,"</d><br/><t>". $row['time14'] ."</t>
</div>
</div>";

echo"
<div  class='box'>
<div class='boxbut'>
<input type='radio' name='datetime' value='". $row['day4']."   ".$row['time15']."'>
<d>". $row['day4'] ,"</d><br/><t>". $row['time15'] ."</t>
</div>
</div>";



echo"
<div  class='box'>
<div class='boxbut'>
<input type='radio' name='datetime' value='". $row['day4']."   ".$row['time16']."'>
<d>". $row['day4'] ,"</d><br/><t>". $row['time16'] ."</t>
</div>
</div>";


  }
  
mysql_close($con);
?> 



</td>
</tr>
<tr>
<tr>
<td>More detail</td>
<td>:</td>
<td><textarea name="detail" cols="40" rows="4" value="detail"></textarea></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td>

Link to comment
Share on other sites

Second would be to test in php if it was selected and simply hide it with css.

 

Can you please tell me how can I do it?

 

 

If you wish I can put together a small tutorial on my blog for you?

 

Thank you, let's start if you can show me how to do it, and I might have other questions related to php coding.

 

Link to comment
Share on other sites

What happens when someone accidentally picks the wrong one?

 

before submitting he/she will be able to change it. They are for bookin time, and I want that only selected one disappears and

other onse still be availeble to select...

 

:shrug:

Link to comment
Share on other sites

You're storing the selected times in your students table, right?

When you select the list of available times from your datetime table (which is a HORRIBLE name for that, rename it "classes" or something), you want to also select all the times from the students table. Then you get the difference. You can do it just in MYSQL, and it will be easy if you give each specific available day and time a unique ID.

This is how it would look with a proper relationship set up and more descriptive names:

SELECT class_id, class_datetime FROM class_times WHERE class_id NOT IN (SELECT class_id FROM enrolled_students)

Link to comment
Share on other sites

You could probable do something like:

 

echo"
<div  class='box'>
<div class='boxbut'>
<input type='radio' name='datetime' value='". $row['day1']."   ".$row['time1']."' " . ( $v_datetime == "$row[day1]   $row[time1]" ? "checked" : "" ) . ">
<d>". $row['day1'] ,"</d><br/><t>". $row['time1'] ."</t>
</div>
</div>";

Link to comment
Share on other sites

It doesn't recognize 'datetime', because this information are from different table on mysql! So I have connection only to the table where this dates are from. Maybe if you take a look at my code, you get my purpose. Date and time for checkbox are from calendar database and datetime table.But the booked time will be stored on another database named College and studens table. So I have to datetime, one is a table and other one is just a row from student. I have only connection to table, where date and time are from, but for checking if checkbox is selected I have to connect form also to another table which is student on college db

 

 

 

And I put this cod and got this errpr:

Undefined index: datetime in C:\xampp\htdocs\form.php on line 98 and here is line 98:

 

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("calendar", $con);

$result = mysql_query("SELECT * FROM datetime  ORDER BY id DESC LIMIT 1");

while($row = mysql_fetch_array($result))
  {



echo"<div class='month' align='center'><input type='hidden' name='month' value='".$row['month']."' ><l>".$row['month']."</l></div>";

echo"
<div  class='box'>
<div class='boxbut'>
<input type='radio' name='datetime' value='". $row['day1']."   ".$row['time1']."' " . ( $v_datetime == "$row[day1]   $row[time1]" ? "checked" : "" ) . ">
<d>". $row['day1'] ,"</d><br/><t>". $row['time1'] ."</t>
</div>
</div>";

 

 

I also put this one, it shows taht chechbox is disabled after being selected, but same error came up!

 

if($_POST['datetime'] != ($row['day1'] . "   " . $row['time1'])) {
    echo"
    <input type='radio' name='datetime' value='". $row['day1']."   ".$row['time1']."' disabled>
    <p>". $row['day1'] ,"</p><br/>". $row['time1'] ."
    // etc
} else {
    echo"
    <input type='radio' name='datetime' value='". $row['day1']."   ".$row['time1']."'>
    <p>". $row['day1'] ,"</p><br/>". $row['time1'] ."
}

 

 

Maybe I have to make connection to student table on college db. But how to connect to tow databases ?

 

 

 

Link to comment
Share on other sites

I have this now, but still it doesn't work !!

 


<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("calendar", $con);

$result = mysql_query("SELECT * FROM datetime  ORDER BY id DESC LIMIT 1");

while($row = mysql_fetch_array($result))
  {



echo"<div class='month' align='center'><input type='hidden' name='month' value='".$row['month']."' ><l>".$row['month']."</l></div>";

$v_datetime='datetime';
$con2=mysql_connect("localhost","root","") or die( "DB connection error:".mysql_error());
$dbcon=mysql_select_db("college",$con2) or die ( "Db Selection error:".mysql_error());
$squ=mysql_query("SELECT * FROM students ");

if($v_datetime!= ($row['day1'] . "   " . $row['time1'])) {
echo"
<div  class='box'>
<div class='boxbut'>
<input type='radio' name='datetime' value='". $row['day1']."   ".$row['time1']."' " . ( $v_datetime == "$row[day1]   $row[time1]" ? "checked" : "" ) . ">
<d>". $row['day1'] ,"</d><br/><t>". $row['time1'] ."</t>
</div>
</div>";
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.