473,386 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

auto select actual month in dropdown box

Hi,

How can I do this,
I've got a little form with a dropdown.

<select name="maand">
<option value='1'>januari</option>
<option value='2'>februari</option>
<option value='3'>maart</option>
<option value='4'>april</option>
<option value='5'>mei</option>
<option value='6'>juni</option>
<option value='7'>juli</option>
<option value='8'>augustus</option>
<option value='9'>september</option>
<option value='10'>oktober</option>
<option value='11'>november</option>
<option value='12'>december</option>
</select>
I would like to select the current month automatically,
but don't know how to do this?
I would start like this (I think)

$maand = S_POST["maand"];
$maandhuidig = date(n);
if($maandhuidig == $maand){
echo?....don't know...}

Many tnx
--
Running GNU/Linux
yvesdm[AT]telenet[dot]be | GnuPG: 0xD590F022
Jabber: yvesdm[AT]jabber.belnet.be
"If windows is the solution, plz give me the problem back!"
Jul 19 '07 #1
10 4346
"YvesDM" <no@way.invalid.bewrote in message
news:LR*******************@phobos.telenet-ops.be...
Hi,

How can I do this,
I've got a little form with a dropdown.

<select name="maand">
<option value='1'>januari</option>
<option value='2'>februari</option>
<option value='3'>maart</option>
<option value='4'>april</option>
<option value='5'>mei</option>
<option value='6'>juni</option>
<option value='7'>juli</option>
<option value='8'>augustus</option>
<option value='9'>september</option>
<option value='10'>oktober</option>
<option value='11'>november</option>
<option value='12'>december</option>
</select>
I would like to select the current month automatically,
but don't know how to do this?
I would start like this (I think)

$maand = S_POST["maand"];
$maandhuidig = date(n);
if($maandhuidig == $maand){
echo?....don't know...}

Many tnx
--
Running GNU/Linux
yvesdm[AT]telenet[dot]be | GnuPG: 0xD590F022
Jabber: yvesdm[AT]jabber.belnet.be
"If windows is the solution, plz give me the problem back!"
The option tag has an attribute of selected. This needs to be set as "yes"
for it to be the selected option. I would make the months/numbers an array,
and then use a while loop to echo them all out. Then, if the month is the
current month, add the option tag with the selected="yes" attribute.

Matt

Jul 19 '07 #2
Matthew White wrote:
The option tag has an attribute of selected. This needs to be set as
"yes"
for it to be the selected option. I would make the months/numbers an
array,
and then use a while loop to echo them all out. Then, if the month is the
current month, add the option tag with the selected="yes" attribute.

Matt
Hi Matt tnx for your answer.
I already resolved this.
My solution is not 100% clean, but it does what I want :-)
I just an extra option on top of the list which has the selected tag
and always takes the value of the current month ;-)

As simple as this:

$monthnow = date("n");
echo <<<EOM
<html>
<form method="post">
<table>
<select name="maand">
<option value='$monthnow'selected>Current month</option>
<option value='1'>januari</option>
<option value='2'>februari</option>
<option value='3'>maart</option>
<option value='4'>april</option>
<option value='5'>mei</option>
<option value='6'>juni</option>
<option value='7'>juli</option>
<option value='8'>augustus</option>
<option value='9'>september</option>
<option value='10'>oktober</option>
<option value='11'>november</option>
<option value='12'>december</option>
</select>
Kind regards,
Yves
--
Running GNU/Linux
yvesdm[AT]telenet[dot]be | GnuPG: 0xD590F022
Jabber: yvesdm[AT]jabber.belnet.be
"If windows is the solution, plz give me the problem back!"
Jul 19 '07 #3
..oO(YvesDM)
>I already resolved this.
My solution is not 100% clean, but it does what I want :-)
I just an extra option on top of the list which has the selected tag
and always takes the value of the current month ;-)
Ugly. Why not just let PHP print out all the options in a simple loop?
You could even let it generate the month names automatically if you want
(assuming proper locale support).
<option value='$monthnow'selected>Current month</option>
There has to be a space between attributes. Additionally it's better
style to not use minimized attributes, but to write them according to
the stricter XHTML rules. This makes it easier to upgrade in the future.
So the result should look like

<option value='7' selected='selected'>Juli</option>

Micha
Jul 19 '07 #4
YvesDM wrote:
Hi,

How can I do this,
I've got a little form with a dropdown.

<select name="maand">
<option value='1'>januari</option>
<option value='2'>februari</option>
<option value='3'>maart</option>
<option value='4'>april</option>
<option value='5'>mei</option>
<option value='6'>juni</option>
<option value='7'>juli</option>
<option value='8'>augustus</option>
<option value='9'>september</option>
<option value='10'>oktober</option>
<option value='11'>november</option>
<option value='12'>december</option>
</select>
I would like to select the current month automatically,
but don't know how to do this?
I would start like this (I think)

$maand = S_POST["maand"];
$maandhuidig = date(n);
if($maandhuidig == $maand){
echo?....don't know...}

Many tnx
imho a better solution. Our lovly god gave us arrays:

<code>
$months = array
(
1 ="januari",
2 ="februari",
3 ="maart",
4 ="april",
5 ="mei",
6 ="juni",
7 ="juli",
8 ="augustus",
9 ="september",
10 ="oktober",
11 ="november",
12 ="december"
);
$selected = date("n");
echo "<select>";
foreach ($months as $i =$v)
{
echo "<option value=\"" . $i . "\"";
if ($i == $selected) echo " selected=\"selected\"";
echo ">" . $v . "</option>";
}
echo "</select>";
</code>
Jul 20 '07 #5
Michael Fesser wrote:
Ugly.
I know, but I'm pretty new to all this.
Also, this is just a simple form on my intranet to check payments.
(ok, i admit, no excuse)
Why not just let PHP print out all the options in a simple loop?
You could even let it generate the month names automatically if you want
(assuming proper locale support).
I will definately try this way after the php/mysql course i will be taking
in september :-)
There has to be a space between attributes. Additionally it's better
style to not use minimized attributes, but to write them according to
the stricter XHTML rules. This makes it easier to upgrade in the future.
So the result should look like
<option value='7' selected='selected'>Juli</option>
Ok, noted that, tnx.

Kind regards
Yves
--
Running GNU/Linux
yvesdm[AT]telenet[dot]be | GnuPG: 0xD590F022
Jabber: yvesdm[AT]jabber.belnet.be
"If windows is the solution, plz give me the problem back!"
Jul 20 '07 #6
..oO(Joe Scylla)
>foreach ($months as $i =$v)
{
echo "<option value=\"" . $i . "\"";
if ($i == $selected) echo " selected=\"selected\"";
echo ">" . $v . "</option>";
}
HTML also allows single quotes (avoids escaping) and variables can be
embedded directly into the string (avoids concatenation).

Just my 2 cents

Micha
Jul 20 '07 #7
Michael Fesser wrote:
.oO(Joe Scylla)
>foreach ($months as $i =$v)
{
echo "<option value=\"" . $i . "\"";
if ($i == $selected) echo " selected=\"selected\"";
echo ">" . $v . "</option>";
}

HTML also allows single quotes (avoids escaping) and variables can be
embedded directly into the string (avoids concatenation).

Just my 2 cents

Micha
it's just my coding style to use only double quotes and never embedd
variables into string.

While theres no difference in using double or single quotes - but
concatenation is much faster than embedd variables into strings.
Jul 20 '07 #8
..oO(Joe Scylla)
>it's just my coding style to use only double quotes
I've seen horrific code with a lot of escaping, concatenation, single-
and double quotes mixed within to build a complex SQL query. It can be
really hard to find a missing quote in such a mess, but YMMV.
>While theres no difference in using double or single quotes - but
concatenation is much faster than embedd variables into strings.
Not necessarily. In the UCNs on php.net you'll find "benchmarks" that
state one or the other

And performance is hardly ever a reason when printing out something.
BTW, the fastest would probably be an echo with a comma-separated list
of arguments.

Micha
Jul 20 '07 #9
On Fri, 20 Jul 2007 18:54:25 +0200, Michael Fesser <ne*****@gmx.dewrote:
>>While theres no difference in using double or single quotes - but
concatenation is much faster than embedd variables into strings.

Not necessarily. In the UCNs on php.net you'll find "benchmarks" that
state one or the other
It should probably be mentioned that PHP 5.2.3 included optimisations in the
way PHP parses and evaluates interpolated strings and heredocs, so any
differences are quite possibly even less noticable in versions from now on.
>And performance is hardly ever a reason when printing out something.
Yep. On a related note, I've recently been using xdebug's profiler option,
feeding the data into kcachegrind - this works quite nicely to find the real
bottlenecks in PHP code:

http://xdebug.org/docs/profiler

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Jul 20 '07 #10
Rik
On Fri, 20 Jul 2007 20:24:39 +0200, Andy Hassall <an**@andyh.co.ukwrote:
Yep. On a related note, I've recently been using xdebug's profiler
option,
feeding the data into kcachegrind - this works quite nicely to find the
real
bottlenecks in PHP code:

http://xdebug.org/docs/profiler
Ooh, very nice, appreciate it!

--
Rik Wasmus
Jul 20 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Prowler | last post by:
In our current application we have a page whose sole purpose for existence is to permit the user to select from a list (subsequent to our login page). We would like to have the list drop down...
8
by: felecha | last post by:
Is there a control that I can put on a Form that would let a user select just the month value? I tried to find a way to make the DateTimePicker or the Month Calendar do what I want but I can't. ...
0
by: Waran | last post by:
I need to create a Auto suggests Textboox like in http://www.google.com/webhp?complete=1&hl=en I have completed this using AJAX.NET for Framework 1.1 . I have some design issues after the data is...
2
by: Abdhul Saleem | last post by:
Hi, Any code snippet or help link available on how to auto resize the dropdown list part of the combo(<select>) ? Or, is there any alternative techniques for displaying the full lenth text...
11
by: eureka | last post by:
Hi All, I'm training in Servlets, JSP and JavaScript, I have a web page in which there's a "StudentName" textbox and below it is a "Names" Dropdown list. Initially the Textbox is empty and...
2
by: rn5a | last post by:
During registration, users have to provide their date of birth. For the date & month part, there are 2 dropdown lists & for the year, there's a textbox. These 3 fields are finally merged together...
4
by: magmike | last post by:
I've got a control on my form that allows the user to select a record based on a form field (in this example, the drop down menu shows the company name, followed by the contact name but uses the...
3
by: =?Utf-8?B?Y21lZWsxXzE5OTk=?= | last post by:
Hello, On a webpage, create an UpdatePanel with two DropDownLists. Set AutoPostBack of DropDownList1 to true. In the SelectedIndexChanged method, refill DropDownList2 and set the focus to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.