I have form that sets a value (choice of a year) from a list of options (range of years) that in turn displays related data in a table (a calendar of months).
My question: how do I set a default value (the current year) so that when the page is first accessed the table is populated with data?
When the page is first accessed table has no data.
Thanks in advance.
Setting a default value to a form
Moderator: General Moderators
-
timbojones
- Forum Newbie
- Posts: 2
- Joined: Mon Jun 26, 2006 6:46 am
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
A default vlaue in the database or a default value on the page?
On the page it's just:
In the database you define it when you create the table:
On the page it's just:
Code: Select all
<select>
<option value="zip">Button</option>
<option value="foo" selected="selected">Bar</option>
</select>Code: Select all
create table foo id int auto_increment primary key, foo varchar(10) default 'bar'Expanding on d11wtq's explanation, for drop downs you select them just like he posted above. While for radio buttons or checkboxes, you use: checked="checked" ; like this...
Code: Select all
<input type="checbox" name="foo" value="1" checked="checked" />
<!-- OR -->
<input type="radio" name="bar" value="bar" checked="checked" />-
timbojones
- Forum Newbie
- Posts: 2
- Joined: Mon Jun 26, 2006 6:46 am
More details . . .
Thanks for the speedy replies!
I have a table displaying the 12 months of the year. The contenst of each cell of the table are generated by php code. The form allows the selection of the year. When the page first displays, no year is selected and no data displays in the table. I want the current year to display when the page first loads.
No database involved with this solution. I'm using the following code in the form:
<form method="post" action="<? echo $_server['PHP_SELF'] ?>">
This is a single, self-contained page.
The 'selected="selected"' approach does not help. The second "database" solution is over my head.
I'm a bit of a newbie at this. Any help greatly appreciated.
Thanks!
I have a table displaying the 12 months of the year. The contenst of each cell of the table are generated by php code. The form allows the selection of the year. When the page first displays, no year is selected and no data displays in the table. I want the current year to display when the page first loads.
No database involved with this solution. I'm using the following code in the form:
<form method="post" action="<? echo $_server['PHP_SELF'] ?>">
This is a single, self-contained page.
The 'selected="selected"' approach does not help. The second "database" solution is over my head.
I'm a bit of a newbie at this. Any help greatly appreciated.
Thanks!