Solved

Making a drop down box in a form sticky.

Posted on 2008-06-21
6
839 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article discusses four methods for overlaying images in a container on a web page
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…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

705 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now