i am working on a dental booking website. it's a school project and i am almost done. but i have 1 major problem and would really appreciate your help.. i have this booking page wherein the client can set date, time and service. on my time, i have set a dropdown for available hours. i would want those hours to be available per day. i was wondering if it is possible to disable an option if it is already booked for that day. i only have these..
i have a table called appointments. columns are ID, userID, reservationDateTime, schedDate, schedTime, service..
<?php
$time = array('8:00 AM', '9:00 AM', '10:00 AM', '11:00 AM','1:00 PM','2:00 PM','3:00 PM','4:00 PM',);
?>
<p>
<label>Time</label><br>
<select name="appTime">
<option>Select Time</option>
<?php
foreach($time as $value){
echo "<option>$value</option>";}
?>
</select>
</p>
<?php
unset($time)
?>
var $selects = $('select');
$selects.on('change', function() {
var $select = $(this),
$options =
$selects.not($select).find('option'),selectedText =
$select.children('option:selected').text();
var $optionsToDisable = $options.filter(function() {
return $(this).text() == selectedText;
});
$optionsToDisable.prop('disabled', true);
});
//to apply initial selection
$selects.eq(0).trigger('change');
echo "<option disabled>$value</option>";
You can use disabled attribute. A disabled option is unusable and un-clickable. This disable all the options (you will like to add some condition...)
<?php
foreach($time as $value){
echo "<option disabled >$value</option>";
}
?>
You could do this:
echo "<option disabled>$value</option>";
<select>
<option value="volvo" disabled>8:00 AM</option>
<option value="saab">9:00 AM</option>
<option value="vw">10:00 AM</option>
<option value="audi">11:00 AM</option>
</select>
If this times are fixed time that you have to show then directly show in option
<p>
<label>Time</label><br>
<select name="appTime">
<option>Select Time</option>
<?php
foreach($time as $time){
?>
<option value="1" <?php if (in_array(1, $time)) {echo "disabled=\"disabled\"";}?>>8:00 AM</option>
<option value="2" <?php if (in_array(2, $time)) {echo "disabled=\"disabled\"";}?>>9:00 AM</option>
<option value="3" <?php if (in_array(3, $time)) {echo "disabled=\"disabled\"";}?>>10:00 AM</option>
<?php }?>
</select>
</p>
Maintain table to save appointment fetch this from table and check is it available if yes the show else disable it.
Related
Let's say I have two select blocks. The first one is the day of the week, the second one is time. In my phpmyadmin database I have a few recordings of day and time (Tuesday, 13.30; Friday 17.00 and so on). So the problem is how can I show only those time for a day as option that are not in database.
First user should select a day. If he selected a day, I record it in a variable and then show him the next select block. I've tried !empty($_POST['day']) but it doesn't work.
I don't understand how I am supposed to record select option value of the day (when user is selecting by clicking on it) to the variable (if user has selected Tuesday $weekday = "tuesday", if Monday, $weekday = "monday") so later I can compare it with recordings in database and skip if there is a recording for the same time of the same day.
I am iterating every half an hour from 9 AM to 11 PM
<select name="day" id="day">
<option value="">Day</option>
<option value="monday">Monday</option>
<option value="tuesday">Tuesday</option>
<option value="wednesday">Wednesday</option>
<option value="thurthday">Thurthday</option>
<option value="friday">Friday</option>
</select>
<?php
$weekday = "";
if(isset($_POST['day'])){
$weekday = $_POST['day'];
}
if( !empty($weekday) ){ ?>
<select name="time" id="time"><?php
for($i = 9; $i < 23; $i+=0.5){?>
<option value="<?php echo $i; ?>"><?php echo $i; ?></option><?php
}?>
</select>
<?php } ?>
So in script tags in my *.php file I've assigned a JavaScript variable with PHP value with all dates records from db like
<script>
let optionsArr = '<?php echo variable_with_values_from_db ?>'
</script>
And then I can check everything using JavaScript and getting change possible variants in further inputs
Last time i post my uncomplete question from my phone.
Now here is my complete question.
Okay So my problem is that i build an edit page editProduct.php. Here i build three forms as i have Three Categories Each Category have its own form. These three forms have almost everything is same.e.g: Product Name input box, condition Select box and more. i view product page when i click edit button edit page open and in a field it show the current value of product in input box and also in select box also in checkbox.Here is my HTML Code.
<input type="text" name="p_name[]" value="<?php echo $db_pname; ?>" placeholder="Product Name">
<select name="guarented-delivery[]" id="guarented-delivery">
<option value="1 Days Shipping" <?php if($db_gdelivery=="1 Days Shipping") { echo 'selected="selected"'; } ?>>1 days</option>
<option value="2 Days shipping" <?php if($db_gdelivery=="2 Days shipping") { echo 'selected="selected"'; } ?>>2 days</option>
<option value="3 Days shipping" <?php if($db_gdelivery=="3 Days shipping") { echo 'selected="selected"'; } ?>>3 days</option>
<option value="5 Days shipping" <?php if($db_gdelivery=="5 Days shipping") { echo 'selected="selected"'; } ?>>5 days</option>
<option value="7 Days shipping" <?php if($db_gdelivery=="7 Days shipping") { echo 'selected="selected"'; } ?>>7 days</option>
<option value="10 Days shipping" <?php if($db_gdelivery=="10 Days shipping") { echo 'selected="selected"'; } ?>>10 days</option>
</select>
Okay so this is the example, and i have three categories and each category form i use same code like this. i use [] with name attribute as it used in all forms so that it get value of all in array. but don't know how to get the value of of selected or new text in input box? as it shows me the old value not new entered value. Here is my php code.
$name = $_POST['p_name'];
foreach($name as $pname)
{
$pname;
// if i echo here then i shows me old product name 3 times echo outside this loop to get value 1 time.
}
echo $pname;
//for dropdown
$gd = $_POST['gdelivery'];
foreach($gd as $gdelivery)
{
$gdelivery;
}
echo $gdelivery;
help me solve this problem. Thanks.
After discussing your comments, this will work for you:
Important is, that all selects must be within the same form.
<form method="post">
<select name="colors[]"><option value="black">black</option></select>
<select name="colors[]"><option value="red">red</option></select>
<select name="colors[]"><option value="gold">gold</option></select>
<input type="submit">
</form>
<?php
$colors = isset($_POST['colors']) ? (array) $_POST['colors'] : [];
foreach($colors as $color)
{
echo "$color<br>\n";
}
// black
// red
// gold
I know this question has been asked before, but I have an unaddressed concern about it.
How can you have a default value that is generated by serverside script?
Ex:
Weekday: <select name="weekday" class="right" value="<% =rs("Weekday")%>">
<option value="Monday">Monday</option>
<option value="Tuesday">Tuesday</option>
<option value="Wednesday">Wednesday</option>
<option value="Thursday">Thursday</option>
<option value="Friday">Friday</option>
<option value="Saturday">Saturday</option>
<option value="Sunday">Sunday</option>
</select>
I know you can have the selected attribute with regular elements, but I'm thrown for a loop here.
Any ideas?
You want your HTML to look something like this eventually - notice the selected after "Friday" to select Friday by default:
<select name="weekday" class="right">
<option value="Monday">Monday</option>
<option value="Tuesday">Tuesday</option>
<option value="Wednesday">Wednesday</option>
<option value="Thursday">Thursday</option>
<option value="Friday" selected>Friday</option>
<option value="Saturday">Saturday</option>
<option value="Sunday">Sunday</option>
</select>
A quick and dirty PHP example can be used like so, where each option is asked to verify whether it is the correct option for the current date. If it is, show selected otherwise don't show anything. You can try this code on http://phpfiddle.org/lite.
<html>
<body>
<select name="weekday" class="right">
<option value="Monday" <?php echo setSelected('Monday'); ?>>Monday</option>
<option value="Tuesday" <?php echo setSelected('Tuesday'); ?>>Tuesday</option>
<option value="Wednesday" <?php echo setSelected('Wednesday'); ?>>Wednesday</option>
<option value="Thursday" <?php echo setSelected('Thursday'); ?>>Thursday</option>
<option value="Friday" <?php echo setSelected('Friday'); ?>>Friday</option>
<option value="Saturday" <?php echo setSelected('Saturday'); ?>>Saturday</option>
<option value="Sunday" <?php echo setSelected('Sunday'); ?>>Sunday</option>
</select>
</body>
</html>
<?php
function setSelected($day)
{
date_default_timezone_set('America/Chicago');
return strtolower($day) === strtolower(date('l')) ? ' selected' : '';
}
?>
I'd be more inclined to create the select/option on the server side itself. Again, quick and dirty PHP example:
<html>
<body>
<select name="weekday" class="right">
<?php
date_default_timezone_set('America/Chicago');
$dayOfWeek = strtolower(date('l'));
$days = array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday');
foreach ($days as $day)
{
echo sprintf("<option value=\"%s\" %s>%s</option>\n",
$day,
$dayOfWeek == strtolower($day) ? 'selected' : '',
$day
);
}
?>
</select>
</body>
</html>
There are 29+ days in a month, I am creating a form using select and option. But this means I will need 31 options for day, 12 for month and a bunch more for the year.
Is there a better way to do it? I'm not looking for plug-ins, I am trying to make some tidy code to replace some old and messy code. Can I use a PHP for loop? And how would I go about doing this? What would it look like (in terms of mixing up the PHP and HTML variables and functions)?
This is not the best way to do this, but is what your asking.
Look:
<select name="d">
<?php for ($i = 1; $i <= 31; $i++): ?>
<option value="<?php echo str_pad($i, 2, '0', STR_PAD_LEFT) ?>"><?php echo $i ?></option>
<?php endfor ?>
</select>
<select name="m">
<?php for ($i = 1; $i <= 12; $i++): ?>
<option value="<?php echo str_pad($i, 2, '0', STR_PAD_LEFT) ?>"><?php echo $i ?></option>
<?php endfor ?>
</select>
and if you need to take the number of the days in the current/specific month use
$current_month = date('m');
$number_of_day_in_month = cal_days_in_month(CAL_GREGORIAN, $current_month , date('Y'));
If you are using HTML5, then create an <input type="date">.
Safari, Opera and Chrome already do support this input type. In browsers with no date-input-support, such an input degrades to a simple text field.
The specs: http://www.w3.org/TR/html-markup/input.date.html
Browser support: http://caniuse.com/#feat=input-datetime
You MUST implement validation on server-side (in PHP in your case) anyway - so text field is not a tragedy. You may also use simple JavaScript to validate user input before submitting the form data as well.
If you want nice calendar widget in all (A-grade-)browsers, you'll need to use a plugin or implement this yourself in JavaScript.
If your trying to simply use HTML (no plugin), this should get you started:
<select name="Month">
<option value="January">January</option>
<option value="February">February</option>
<option selected value="March">March</option>
</select>
<select name="Day">
<option value="1">1</option>
<option value="2">2</option>
<option selected value="3">3</option>
</select>
<select name="Year">
<option value="2013">2013</option>
<option value="2012">2012</option>
<option selected value="2011">2011</option>
</select>
Here's the jsfiddle
But I would recommend a JavaScript solution, like jQuery's datepicker (http://jqueryui.com/datepicker/).
I'm using search with combo box
Here is my combo box source code
<select name="salary" class="styled">
<option selected="selected" value=''>Any</option>
<option value="10000">10,000</option>
<option value="20000">20,000</option>
<option value="30000">30,000</option>
<option value="40000">40,000</option>
<option value="50000">50,000</option>
<option value="60000">60,000</option>
<option value="70000">70,000</option>
<option value="80000">80,000</option>
<option value="90000">90,000</option>
<option value="100000">100,000</option>
<option value="110000">110,000</option>
<option value="120000">120,000</option>
<option value="130000">130,000</option>
<option value="140000">140,000</option>
<option value="150000">150,000</option>
</select>
I would like to select value based on $salary=$_GET['salary']; if $salary empty I need to select first one as selected
To set a default value for an HTML select element, you need to give the appropriate <option> element the selected attribute. It would look like this:
<option value='50000' selected='selected'>50,000</option>
In your PHP code, you would add this by setting a string for each option, to either "selected='selected'" or blank, depending on whether that option is the one you want to have selected.
This is obviously far easier to put into a loop rather than writing the same code twenty times, so you would need to rewrite your output to create a loop for creating your options.
Hope that helps.
You can do something like this on creation...[not tested]
<?php
$options = array(
'10000' => '10,000',
...
'150000' => '150,000'
); //From MySQL
array_unshift($options, '' => 'Any');
$salary = isset($_GET['salary'])?$_GET['salary']:'';
?>
<select name="salary" class="styled">
<?php foreach ($options as $value=>$text){ ?>
<option <?php if($value == $salary){echo 'selected="selected"'; }?> value="<?php echo $value; ?>"><?php echo $text; ?></option>
<?php } ?>
</select>
If I understand your question correctly you want that if the person doesn't select any thing you want 10000 to be automatically selected for him. And I also assume that the options in the select list are static. So..
<?php
if($_GET['salary']=='')
$salary = 10000;
else
$salary = $_GET['salary'];
?>