Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Making a drop down box in a form sticky.

Posted on 2008-06-21
6
Medium Priority
?
853 Views
Last Modified: 2008-09-24
HI there I have two drop down boxes. One to select the time and another to select the price of an event.

Basically I want them to be sticky so if the form is submitted and there is a mistake I want the form to remeber the value.

I've included two parts to my script the

the drop down boxes:

Event start time:<select name="eventtime">
 
<option value="00:00:00">00:00</option>
<option value="00:30:00">00:30</option>
<option value="01:00:00">01:00</option>
<option value="01:30:00">01:30</option>
<option value="02:00:00">02:00</option>
<option value="02:30:00">02:30</option>
<option value="03:00:00">03:00</option>
<option value="03:30:00">03:30</option>
<option value="04:00:00">04:00</option>
 
<option value="04:30:00">04:30</option>
<option value="05:00:00">05:00</option>
<option value="05:30:00">05:30</option>
<option value="06:00:00">06:00</option>
<option value="06:30:00">06:30</option>
<option value="07:00:00">07:00</option>
<option value="07:30:00">07:30</option>
<option value="08:00:00">08:00</option>
<option value="08:30:00">08:30</option>
 
<option value="09:00:00">09:00</option>
<option value="09:30:00">09:30</option>
<option value="10:00:00">10:00</option>
<option value="10:30:00">10:30</option>
<option value="11:00:00">11:00</option>
<option value="11:30:00">11:30</option>
<option value="12:00:00">12:00</option>
<option selected="selected" value="">SELECT</option>
<option value="12:30:00">12:30</option>
 
<option value="13:00:00">13:00</option>
<option value="13:30:00">13:30</option>
<option value="14:00:00">14:00</option>
<option value="14:30:00">14:30</option>
<option value="15:00:00">15:00</option>
<option value="15:30:00">15:30</option>
<option value="16:00:00">16:00</option>
<option value="16:30:00">16:30</option>
<option value="17:00:00">17:00</option>
 
<option value="17:30:00">17:30</option>
<option value="18:00:00">18:00</option>
<option value="18:30:00">18:30</option>
<option value="19:00:00">19:00</option>
<option value="19:30:00">19:30</option>
<option value="20:00:00">20:00</option>
<option value="20:30:00">20:30</option>
<option value="21:00:00">21:00</option>
<option value="21:30:00">21:30</option>
 
<option value="22:00:00">22:00</option>
<option value="22:30:00">22:30</option>
<option value="23:00:00">23:00</option>
<option value="23:30:00">23:30</option>
</select> Entry price:<select name="eventprice">
<option selected="selected" value="">SELECT</option>
<option value="Free">Free</option>
<option value="£1">£1</option>
 
<option value="£2">£2</option>
<option value="£3">£3</option>
<option value="£4">£4</option>
<option value="£5">£5</option>
<option value="£6">£6</option>
<option value="£7">£7</option>
<option value="£8">£8</option>
<option value="£9">£9</option>
<option value="£10">£10</option>
 
<option value="£11">£11</option>
<option value="£12">£12</option>
<option value="£13">£13</option>
<option value="£14">£14</option>
<option value="£15">£15</option>
<option value="£16">£16</option>
<option value="£17">£17</option>
<option value="£18">£18</option>
<option value="£19">£19</option>
 
<option value="£20">£20</option>
<option value="£25">£25</option>
<option value="£30">£30</option>
<option value="£40">£40</option>
<option value="£50">£50</option>
</select>

(sorry for the length)

and the php validation as a code snippet

Thanks in advance,

Daniel
if (!empty($_POST['eventtime'])) {
  $etm = escape_data($_POST['eventtime']);
 
} else {
 
  $etm = NULL;
  echo '<p><font color="red" size="+1">Please enter a time for the event.</font></p>';
  
}
 
// Check for entry price
 
if (!empty($_POST['eventprice'])) {
  $epr = escape_data($_POST['eventprice']);
 
} else {
 
  $epr = NULL;
  echo '<p><font color="red" size="+1">Please enter a price for the event.</font></p>';
  
}

Open in new window

0
Comment
Question by:dm404
  • 3
  • 3
6 Comments
 
LVL 4

Expert Comment

by:afzz
ID: 21836898
try this
Event start time:<select name="eventtime">
 
<option value="00:00:00">00:00</option>
<option value="00:30:00">00:30</option>
<option value="01:00:00">01:00</option>
<option value="01:30:00">01:30</option>
<option value="02:00:00">02:00</option>
<option value="02:30:00">02:30</option>
<option value="03:00:00">03:00</option>
<option value="03:30:00">03:30</option>
<option value="04:00:00">04:00</option>
 
<option value="04:30:00">04:30</option>
<option value="05:00:00">05:00</option>
<option value="05:30:00">05:30</option>
<option value="06:00:00">06:00</option>
<option value="06:30:00">06:30</option>
<option value="07:00:00">07:00</option>
<option value="07:30:00">07:30</option>
<option value="08:00:00">08:00</option>
<option value="08:30:00">08:30</option>
 
<option value="09:00:00">09:00</option>
<option value="09:30:00">09:30</option>
<option value="10:00:00">10:00</option>
<option value="10:30:00">10:30</option>
<option value="11:00:00">11:00</option>
<option value="11:30:00">11:30</option>
<option value="12:00:00">12:00</option>
<option selected="selected" value="<?=$etm==""?"":"$etm"?>"><?=$etm==""?"SELECT":"$etm"?></option>
<option value="12:30:00">12:30</option>
 
<option value="13:00:00">13:00</option>
<option value="13:30:00">13:30</option>
<option value="14:00:00">14:00</option>
<option value="14:30:00">14:30</option>
<option value="15:00:00">15:00</option>
<option value="15:30:00">15:30</option>
<option value="16:00:00">16:00</option>
<option value="16:30:00">16:30</option>
<option value="17:00:00">17:00</option>
 
<option value="17:30:00">17:30</option>
<option value="18:00:00">18:00</option>
<option value="18:30:00">18:30</option>
<option value="19:00:00">19:00</option>
<option value="19:30:00">19:30</option>
<option value="20:00:00">20:00</option>
<option value="20:30:00">20:30</option>
<option value="21:00:00">21:00</option>
<option value="21:30:00">21:30</option>
 
<option value="22:00:00">22:00</option>
<option value="22:30:00">22:30</option>
<option value="23:00:00">23:00</option>
<option value="23:30:00">23:30</option>
</select> Entry price:<select name="eventprice">
<option selected="selected" value="<?=$epr==""?"":"$epr"?>"><?=$epr==""?"SELECT":"$epr"?></option>
<option value="Free">Free</option>
<option value="£1">£1</option>
 
<option value="£2">£2</option>
<option value="£3">£3</option>
<option value="£4">£4</option>
<option value="£5">£5</option>
<option value="£6">£6</option>
<option value="£7">£7</option>
<option value="£8">£8</option>
<option value="£9">£9</option>
<option value="£10">£10</option>
 
<option value="£11">£11</option>
<option value="£12">£12</option>
<option value="£13">£13</option>
<option value="£14">£14</option>
<option value="£15">£15</option>
<option value="£16">£16</option>
<option value="£17">£17</option>
<option value="£18">£18</option>
<option value="£19">£19</option>
 
<option value="£20">£20</option>
<option value="£25">£25</option>
<option value="£30">£30</option>
<option value="£40">£40</option>
<option value="£50">£50</option>
</select>

Open in new window

0
 

Author Comment

by:dm404
ID: 21837093
Hi afzz,

The code above brings about an error. The error says that $epr and $etm are undefined variables.

It may need an if (isset($_POST['eventdate'] sort of clause?

Thanks in advance!

Daniel
0
 
LVL 4

Expert Comment

by:afzz
ID: 21837249
at the top of your script initialize the variables as shown below and try

$etm = "";
$epr = "";
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:dm404
ID: 21837304
HI afzz,

it still says there is an error in defining the variables :(

This is how I defined the variables

// Check for event time

if (!empty($_POST['eventtime'])) {
  $etm = escape_data($_POST['eventtime']);

} else {

$etm = "";

  echo '<p><font color="red" size="+1">Please enter a time for the event.</font></p>';
 
}

// Check for entry price

if (!empty($_POST['eventprice'])) {
  $epr = escape_data($_POST['eventprice']);

} else {

$epr = "";
  echo '<p><font color="red" size="+1">Please enter a price for the event.</font></p>';
 
}
0
 
LVL 4

Accepted Solution

by:
afzz earned 1500 total points
ID: 21837809
The code if (!empty($_POST['eventtime'])) { is within a condition. That is only if there has been a post to the script this is initialized

your code above will not initialize the variables unless there is a post action to the script.

Therefore above everything else add this.

$etm = "";
$epr = "";
and after that add

if (!empty($_POST['eventtime'])) {
......
0
 

Author Comment

by:dm404
ID: 21840145
Hi Afzz,

It is still coming up with the same error even though I set the variables above the condition : s.

Thanks again,

Dan
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question