Solved

Making a drop down box in a form sticky.

Posted on 2008-06-21
6
849 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

624 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