473,503 Members | 11,018 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Assigning values back to drop down box

TG
Group,

I have several drop down boxes that I'd like to repopulate with the value
the user selected -- after the form posts by calling itself -- these fields
are blanked out. I am having difficulty getting the drop downs to repopulate
with the values the user's selected. If any of you have implemented this
before, how have you done this and what is the syntax?

Thanks,
Jul 17 '05 #1
7 8181
"TG" <tg********@cox.net> schrieb:
I have several drop down boxes that I'd like to repopulate with the value
the user selected -- after the form posts by calling itself -- these fields
are blanked out. I am having difficulty getting the drop downs to repopulate
with the values the user's selected. If any of you have implemented this
before, how have you done this and what is the syntax?


This is pure HTML.

Option 2 is set:

<option value="1"></option>
<option value="2" selected='selected'></option>
<option value="3"></option>

Regards,
Matthias
Jul 17 '05 #2
>...repopulate with the value the user selected -- after the form posts by calling itself -- these fields
...with the values the user's selected. If any of you have implemented this


Here is some sample code that should get you going:

<?php

/* this is the form handling code */
$myselect = '';
if ( isset( $_POST['myselect'] ) ) { $myselect = $_POST['myselect'] ; }
if ( isset( $_GET['myselect'] ) ) { $myselect = $_GET['myselect'] ; }

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Form Select Handler</title>
</head>

<body>
<form action="<?php $_SERVER['PHP_SELF']; ?>" name="myform" id="myform" method="GET">
<select name="myselect" id="myselect">
<option value="1" <?php print ($myselect==1) ? 'SELECTED' : ''; ?>>option1</option>
<option value="2" <?php print ($myselect==2) ? 'SELECTED' : ''; ?>>option2</option>
</select>
<input type="submit">
</form>
</body>
</html>
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~
Wil Moore III, MCP Site : www.quicksitedesign.com?em
Application Developer Site : www.digitallysmooth.com?em
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~
Jul 17 '05 #3
On 2004-01-14, laidbak <la*******@hotmail.com> wrote:
This is a multi-part message in MIME format.

------=_NextPart_000_0276_01C3DA2C.59E54640
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


Only posts in plaintext please.
Jul 17 '05 #4
"laidbak" <la*******@hotmail.com> wrote:
<div><font face=Arial size=2></font>&nbsp;</div>
<div><font face=Courier color=#800000 size=2>&lt;?php</font></div>
<div><font face=Courier color=#800000></font>&nbsp;</div>

<div><font face=Courier color=#800000 size=2>
&nbsp;&nbsp;&nbsp; /* this is the form handling code */<br>
&nbsp;&nbsp;&nbsp; $myselect = '';<br>
&nbsp;&nbsp;&nbsp; if ( isset( $_POST['myselect'] ) ) { $myselect = $_POST['myselect'] ; }<br>
&nbsp;&nbsp;&nbsp; if ( isset( $_GET['myselect'] ) ) { $myselect = $_GET['myselect'] ; }
</font></div>
<div><font face=Courier color=#800000></font>&nbsp;</div>
<div><font face=Courier color=#800000 size=2>?&gt;<br>
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;</font></div>
<div><font face=Courier color=#800000></font>&nbsp;</div>
<div><font face=Courier color=#800000 size=2>&lt;html&gt;<br>
&lt;head&gt;<br>
&nbsp;&lt;title&gt;Form Select Handler&lt;/title&gt;<br>
&lt;/head&gt;
</font></div>

<div><font face=Courier color=#800000></font>&nbsp;</div>
<div><font face=Courier color=#800000 size=2>&lt;body&gt;<br>
&lt;form action="&lt;?php $_SERVER['PHP_SELF']; ?&gt;" name="myform" id="myform" method="GET"&gt;<br>
&lt;select name="myselect" id="myselect"&gt;<br>
&nbsp;&lt;option value="1" &lt;?php print ($myselect==1) ? 'SELECTED' : ''; ?&gt;&gt;option1&lt;/option&gt;<br>
&nbsp;&lt;option value="2" &lt;?php print ($myselect==2) ? 'SELECTED' : ''; ?&gt;&gt;option2&lt;/option&gt;<br>
&lt;/select&gt;<br>
&lt;input type="submit"&gt;<br>
&lt;/form&gt;<br>
&lt;/body&gt;<br>
&lt;/html&gt;</font></div>

<div><font face=Arial size=2></font>&nbsp;</div>


This looks very complicated.

SCNR,
Matthias
Jul 17 '05 #5
"TG" <tg********@cox.net> wrote in message news:<Pu5Nb.3235$Mb7.2047@lakeread04>...
Group,

I have several drop down boxes that I'd like to repopulate with the value
the user selected -- after the form posts by calling itself -- these fields
are blanked out. I am having difficulty getting the drop downs to repopulate
with the values the user's selected. If any of you have implemented this
before, how have you done this and what is the syntax?

Thanks,


Use a select box like following:

[HTML]
<select name="mySelect">
<option value="1" <?=$mySelectOption['1']?>>option1</option>
<option value="2" <?=$mySelectOption['2']?>>option2</option>
<option value="3" <?=$mySelectOption['3']?>>option3</option>
<option value="4" <?=$mySelectOption['4']?>>option4</option>
<option value="5" <?=$mySelectOption['5']?>>option5</option>
<option value="6" <?=$mySelectOption['6']?>>option6</option>
</select>
[/HTML]

And code your PHP like following:

[PHP]
$mySelectOption['1'] =
$mySelectOption['2'] =
$mySelectOption['3'] =
$mySelectOption['4'] =
$mySelectOption['5'] =
$mySelectOption['6'] = '';
if(!empty($_REQUEST['mySelect']))
$mySelectOption[$_REQUEST['mySelect']] = 'selected';
else
$mySelectOption[1] = 'selected'; // Default selected, for first time

[/PHP]

This is just a possible way to achieve this.
Another method will be output your Select box in a loop and check for
selected condition, and ouput the *selected* text when necessary.

--
Cheers,
Rahul
Jul 17 '05 #6
"Matthias Esken" <mu******************@usenetverwaltung.org> wrote in message
news:bu**********@usenet.esken.de...
"laidbak" <la*******@hotmail.com> wrote:
<div><font face=Arial size=2></font>&nbsp;</div>
<div><font face=Courier color=#800000 size=2>&lt;?php</font></div>
<div><font face=Courier color=#800000></font>&nbsp;</div>
<snip>
This looks very complicated.


That's because it is an HTML reply post, which your newsreader apparently
does not understand. That is the reason HTML posts on usenet are discouraged.
(http://www.usenet.org.uk/ukpost.html#s2)
Jul 17 '05 #7
Personally I like to do this:

<? $selected = array($menu => "selected"); ?>
<select name="menu">
<option value="1" <?=$selected[1]?>>Item 1</option>
<option value="2" <?=$selected[2]?>>Item 2</option>
<option value="3" <?=$selected[3]?>>Item 3</option>
</select>

Uzytkownik "TG" <tg********@cox.net> napisal w wiadomosci
news:Pu5Nb.3235$Mb7.2047@lakeread04...
Group,

I have several drop down boxes that I'd like to repopulate with the value
the user selected -- after the form posts by calling itself -- these fields are blanked out. I am having difficulty getting the drop downs to repopulate with the values the user's selected. If any of you have implemented this
before, how have you done this and what is the syntax?

Thanks,

Jul 17 '05 #8

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

Similar topics

9
3648
by: Matt | last post by:
I have 2 drop down boxes. When the user changes the values in one drop down box, the values in another drop down box will be changed on the fly. Is it possible to do that? in client side or...
2
3612
by: Chris Becker | last post by:
This is my attempt to rephrase a question I asked earlier that got no response. I suspect it was my poor/unplanned wording. Here is another attempt: I have a form with some drop down lists. I...
5
2229
by: Rob Wire | last post by:
For the code below, how could I add an item in the drop down lists for both company and location to be an "All" selection that would send to the stored proc. spRptAttachments a value of "%" so...
2
12345
by: macyp | last post by:
I have to pass values from one aspx page to another. The controls I have in the first page are: a textbox, 3 drop down lists, and 2 check boxes, and a submit button. It is a search page, and the...
3
2393
by: Penny Bond | last post by:
Hi, Any help or suggestions on this one would be gratefully appreciated: I have 2 aspx pages one is called 'Query' and the other 'Details'. Query page has a number of text boxes and drop...
19
9062
by: nazgulero | last post by:
Hello all, I wonder if anybody can give me a hint about what I have to do to get this working: I am creating a drop down box using the script below. The result is two text fields; now I want...
1
2347
by: Per | last post by:
Hi, I have a problem that I can't figure out. I have a database application to keep track of boxes that contain files. For data entry, I have a form with a main form section for the box-specific...
2
1782
by: Jim Gregg | last post by:
Hello all, I am faced with some logic that I am unsure how to handle. Imagine that I am running a WMI query and I am outputting the data into a dynamically created ASP table control. Here is my...
4
1514
by: gotonagle | last post by:
hi , i m new to asp and leraning it... i have only one page in which i take some values like name, dob and education degree. after post back i return to this page iteslf.. but the values in...
0
7095
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
7294
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,...
0
7361
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7015
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7470
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5602
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4693
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1523
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.