Set current date in form select lists - html

Basically I have HTML form which reads in a date from a user, for a hotel booking system.
I have 3 lists, one for day, one for month and one for year.
<SELECT NAME="month">
<OPTION VALUE="1"> Jan
<OPTION VALUE="2"> Feb
<OPTION VALUE="3"> March and so on
</SELECT>
and the same for year(2010 - 2013) and day(1 -31).
Is there any way I can have the default value in the day list set to the current day, the default value in the month list set the the current month, and the default value in the year list set to the current year? Rather than manually having to do it.
Thanks in advance for the help!

You will need to use JavaScript. Here's an example, using jQuery:
<script type="text/javascript">
$(document).ready(function(){
var CurrentDate=new Date();
$("#year").val(CurrentDate.getYear());
$("#month").val(CurrentDate.getMonth());
$("#day").val(CurrentDate.getDate());
});
</script>
Here's the code in action.

You will have to use javascript. or any client side scripting to do this. I can suggest you some examples but you must first understand the concept of client side scripting

In response to #sushil bharwani you can also use a server side language if you are comfortable with that. PHP is installed on most web hosts you find now days and a plus (as opposed to javascript) is that it is guaranteed to work. The clients user agent does not matter.

This is php code:
<?php
$month = date('F');
if($month == "January") { $jan = "selected"; }
if($month == "February") { $feb = "selected"; }
if($month == "March") { $mar = "selected"; }
if($month == "April") { $apr = "selected"; }
if($month == "May") { $may = "selected"; }
if($month == "June") { $june = "selected"; }
if($month == "July") { $july = "selected"; }
if($month == "August") { $aug = "selected"; }
if($month == "September") { $sep = "selected"; }
if($month == "Octomber") { $oct = "selected"; }
if($month == "November") { $nov = "selected"; }
if($month == "December") { $dec = "selected"; }
?>
Now select below code, then copy and paste between the body-tag:
<select name="start_month" id="start_month">
<option value="January" <?php echo $jan; ?> >January</option>
<option value="February" <?php echo $feb; ?> >February</option>
<option value="March" <?php echo $march; ?> >March</option>
<option value="April" <?php echo $apr; ?> >April</option>
<option value="May" <?php echo $may; ?> >May</option>
<option value="June" <?php echo $june; ?> >June</option>
<option value="July" <?php echo $july; ?> >July</option>
<option value="August" <?php echo $aug; ?> >August</option>
<option value="September" <?php echo $sep; ?> >September</option>
<option value="Octomber" <?php echo $oct; ?> >Octomber</option>
<option value="November" <?php echo $nov; ?> >November</option>
<option value="December" <?php echo $dec; ?> >December</option>
</select>
Thanks.
Note: Link for the complete example: http://www.javascriptkit.com/script/script2/curdateform2.shtml

Related

can we make slider in select options?

can we make slider/carousel in select options.below is the code and image.anyone help plz.
<select class="" id="project_type" name="project_type" title="Project Type" multiple
style="width: 410px;">
<option value="Residential" <?php if($selected_project_type == 'Residential') echo "selected";
?> >Residential</option>
<option value="Commercial" <?php if($selected_project_type == 'Commercial') echo "selected"; ?
> >Commercial</option>
<option value="Residential & Commercial" <?php if($selected_project_type == 'Residential &
Commercial') echo "selected"; ?> >Residential & Commercial</option>
<option value="Infrastructure" <?php if($selected_project_type == 'Infrastructure') echo
"selected"; ?> >Infrastructure</option>
<option value="Others" <?php if($selected_project_type == 'Others') echo "selected"; ?>
>Others</option>
enter image description here
i want all select options inline and put slider.
Selects are pretty hard to customize
A way easier will be just make slider
and change an input or even div properties when click on slide

how to keep selected value in select box after submit or page reload were values and option are different which retrieved from db?

I want to keep selected particular value which was selected before the form submission. But after reloading or submisssion i did not get the previous selected value.help me!
<select name="select" class="dropbtn" onchange="this.form.submit()">
<?php
include 'connect.php';
$query="SELECT * FROM `user` WHERE id =1";
$result=mysqli_query($link_id,$query);
while($data = mysqli_fetch_assoc($result))
{ ?>
<option value="<?php echo $data['user_id']; ?>"> <?php echo
$data['address']; ?> </option>
<?php } ?>
</select>
<?php
$id = null;
if(isset($_POST['select']))
{
$id = $_POST['select'];
echo $id;
}
?>

Option Value placed outside of quotes

While I am sure I am doing something stupid, after staring at the code for much too long, I am now stumped. I have created a select box and populate it with posts from a certain post type in Wordpress. This works fine except when viewing the source, the option value is being placed outside of the actual value attribute and all boxes are being marked as selected.
It has to be a simple mistake somewhere but if anyone can spot this, it would be greatly appreciated.
<label for="meta-select-providers" class="package-row-title"><?php _e( 'Provider', 'package_textdomain' )?></label>
<select name="meta-select-providers" id="meta-select-providers">
<?
if( $providers->have_posts() )
{
while( $providers->have_posts() )
{
$providers->the_post();
$provider_name = get_the_title();
$provider_id = the_ID();
?>
<option value="<? echo $provider_id; ?>" <?php if (isset ($package_stored_meta['meta-select-providers'])) selected( $package_stored_meta['meta-select-providers'][0], $provider_id ); ?>>
<?php _e( $provider_name, 'package_textdomain' )?></option>
<?
}
}
?>
</select>
Update
<option value="<? the_ID(); ?>" <?php if (isset ($package_stored_meta['meta-select-providers'])) selected( $package_stored_meta['meta-select-providers'][0], the_ID() ); ?>>
<?php _e( $provider_name, 'package_textdomain' )?></option>
Source:
1647
<option value="" selected>
Post 1</option>
1645
<option value="" selected>
Post 2</option>
1643
<option value="" selected>
Post 3</option>
the_ID() displays (echoes) the value. From the docs:
Displays the numeric ID of the current post. This tag must be within The Loop.
Note: This function displays the ID of the post, to return the ID use get_the_ID().
This code will work as expected:
<label for="meta-select-providers" class="package-row-title"><?php _e( 'Provider', 'package_textdomain' )?></label>
<select name="meta-select-providers" id="meta-select-providers">
<?
if( $providers->have_posts() )
{
while( $providers->have_posts() )
{
$providers->the_post();
$provider_name = get_the_title();
$provider_id = get_the_ID();
?>
<option value="<? echo $provider_id; ?>" <?php if (isset ($package_stored_meta['meta-select-providers'])) selected( $package_stored_meta['meta-select-providers'][0], $provider_id ); ?>>
<?php _e( $provider_name, 'package_textdomain' )?></option>
<?
}
}
?>
</select>

HTML/CSS Form (Table) DOB line showing on two lines

On my websites form - my date of birth day, month and year menus are showing on two lines, I'd like them to all show on the same line instead.
When I test the code it show's on one line so I believe there must be a width issue.
You can see the issue on the right hand form (incomeprotectionstore.co.uk).
Any help would be much appreciated.
The date of birth css can be seen below:
<tr>
<td nowrap=""><label><div align="left">Date of birth</div></label></td>
<td><select name="x_C1DOB_YYYY" id="dd_dob_year" class="input-dob">
<?
for($i=1995; $i >= 1900; $i--){
?>
<OPTION value="<? echo $i; ?>" <? formSelected( $x_C1DOB_YYYY, $i ); ?>><? echo $i; ?></OPTION>
<?
}
?>
</select>
<select name="x_C1DOB_MM" id="dd_dob_month" class="input-dob">
<?
for($i=1; $i<=12; $i++){
if($i < 10) $x = "0".$i; else $x = $i;
$month = $month_name[$i-1];
?>
<OPTION value="<? echo $x; ?>" <? formSelected( $x_C1DOB_MM, $x ); ?>><? echo $month; ?></OPTION>
<?
}
?>
</select>
<select name="x_C1DOB_DD" id="dd_dob_day" class="input-dob">
<?
for($i=1; $i<=31; $i++){
if($i < 10) $x = "0".$i; else $x = $i;
?>
<OPTION value="<? echo $x; ?>" <? formSelected( $x_C1DOB_DD, $x ); ?>><? echo $x; ?></OPTION>
<?
}
?> </select>
</td>
</tr>
Thanks,
Sam
You could try wrapping your selects in an element that prevents line-wrapping like this:
<div style="white-space:nowrap;">
<select>
<select>
<select>
</div>
Set width:200px; on the <td> containing the DOB dropdowns (like it is set on the <input>s in the rest of the form)
for instance <td class = "dob-wrapper"> in the HTML and .dob-wrapper { width:200px; } in the CSS
Final answer:
Change the first <td> to <td style="width:99px;"> Then change the second <td> element to <td style="width:200px;">
If you want the boxes on the right instead of left change use 160px instead of 99px
this is the working code of birthday. try this
<div id="birthday">
<p>Birthday</p>
<table id="birthday">
<tr>
<th>
<select name="month">
<option value="">Month</option>
<option value="01" <?php if(isset($_POST['month']) && $_POST['month'] == '01') { echo 'selected="selected"'; } ?>>Jan</option>
<option value="02" <?php if(isset($_POST['month']) && $_POST['month'] == '02') { echo 'selected="selected"'; } ?>>Feb</option>
<option value="03" <?php if(isset($_POST['month']) && $_POST['month'] == '03') { echo 'selected="selected"'; } ?>>Mar</option>
<option value="04" <?php if(isset($_POST['month']) && $_POST['month'] == '04') { echo 'selected="selected"'; } ?>>Apr</option>
<option value="05" <?php if(isset($_POST['month']) && $_POST['month'] == '05') { echo 'selected="selected"'; } ?>>May</option>
<option value="06" <?php if(isset($_POST['month']) && $_POST['month'] == '06') { echo 'selected="selected"'; } ?>>Jun</option>
<option value="07" <?php if(isset($_POST['month']) && $_POST['month'] == '07') { echo 'selected="selected"'; } ?>>Jul</option>
<option value="08" <?php if(isset($_POST['month']) && $_POST['month'] == '08') { echo 'selected="selected"'; } ?>>Aug</option>
<option value="09" <?php if(isset($_POST['month']) && $_POST['month'] == '09') { echo 'selected="selected"'; } ?>>Sep</option>
<option value="10" <?php if(isset($_POST['month']) && $_POST['month'] == '10') { echo 'selected="selected"'; } ?>>Oct</option>
<option value="11" <?php if(isset($_POST['month']) && $_POST['month'] == '11') { echo 'selected="selected"'; } ?>>Nov</option>
<option value="12" <?php if(isset($_POST['month']) && $_POST['month'] == '12') { echo 'selected="selected"'; } ?>>Dec</option>
</select>
</th>
<th>
<select id="day" name="day">
<option value="">Day</option>
<?php
for($i=1; $i<=31; $i++)
{
echo '<option value="' . $i . '"';
if(isset($_POST['day']) && $_POST['day'] == $i)
{
echo ' selected="selected"';
}
echo '>' . $i . '</option>';
}
?>
</select>
</th>
<th>
<select id="year" name="year">
<option value="">Year</option>
<?php
for($i=2014; $i>=1905; $i--)
{
echo '<option value="' . $i . '"';
if(isset($_POST['year']) && $_POST['year'] == $i)
{
echo ' selected="selected"';
}
echo '>' . $i . '</option>';
}
?>
</select>
</th>
</tr>
</table>
</div>

html select list selected item and maximum value can be selected

HELLO,
i have an html select list, and i want: the selected number to be a given value $content->number, and the maximum value to be $content->product_type->stock_2 if it is less than 5, or 5 if it is greater than 5.
now i have:
<select class="number" name="number">
<? $max = $content->product_type->stock_2 > 5 ? 5 : $content->product_type->sale_stock; ?>
<option value="<?= $content->number ?>"><?= $content->number; ?> </option>
<? for ($i = 1; $i <= $max; $i++):?>
<option <?php if($content->product_type->stock_2 == $i) echo 'selected="selected"' ;?> value="<?= $i ?>"><?= $i; ?></option>
<? endfor; ?>
</select>
but it shows me twice the selected value $content->number. i'm sure i am mistaking somewhere.
Any suggestions?
thank you!
I do not know whether I correct understood what you want to do, but try this:
<select class="number" name="number">
<? $max = $content->product_type->stock_2 > 5 ? 5 : $content->product_type->sale_stock; ?>
<option value="<?= $content->number ?>"><?= $content->number; ?> </option>
<? for ($i = 1; $i <= $max; $i++):?>
<? if ($i != $content->number): ?>
<option <?php if($content->product_type->stock_2 == $i) echo 'selected="selected"' ;?> value="<?= $i ?>"><?= $i; ?></option>
<? endif; ?>
<? endfor; ?>
</select>