473,657 Members | 2,477 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 8196
"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='selec ted'></option>
<option value="3"></option>

Regards,
Matthias
Jul 17 '05 #2
>...repopulat e 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*******@hotm ail.com> wrote:
This is a multi-part message in MIME format.

------=_NextPart_000_ 0276_01C3DA2C.5 9E54640
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


Only posts in plaintext please.
Jul 17 '05 #4
"laidbak" <la*******@hotm ail.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;&nb sp; /* this is the form handling code */<br>
&nbsp;&nbsp;&nb sp; $myselect = '';<br>
&nbsp;&nbsp;&nb sp; if ( isset( $_POST['myselect'] ) ) { $myselect = $_POST['myselect'] ; }<br>
&nbsp;&nbsp;&nb sp; 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;?ph p $_SERVER['PHP_SELF']; ?&gt;" name="myform" id="myform" method="GET"&gt ;<br>
&lt;select name="myselect" id="myselect"&g t;<br>
&nbsp;&lt;optio n value="1" &lt;?php print ($myselect==1) ? 'SELECTED' : ''; ?&gt;&gt;option 1&lt;/option&gt;<br>
&nbsp;&lt;optio n value="2" &lt;?php print ($myselect==2) ? 'SELECTED' : ''; ?&gt;&gt;option 2&lt;/option&gt;<br>
&lt;/select&gt;<br>
&lt;input type="submit"&g t;<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.323 5$Mb7.2047@lake read04>...
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" <?=$mySelectOpt ion['1']?>>option1</option>
<option value="2" <?=$mySelectOpt ion['2']?>>option2</option>
<option value="3" <?=$mySelectOpt ion['3']?>>option3</option>
<option value="4" <?=$mySelectOpt ion['4']?>>option4</option>
<option value="5" <?=$mySelectOpt ion['5']?>>option5</option>
<option value="6" <?=$mySelectOpt ion['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($_REQ UEST['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************ ******@usenetve rwaltung.org> wrote in message
news:bu******** **@usenet.esken .de...
"laidbak" <la*******@hotm ail.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@laker ead04...
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
3659
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 server side? what's the best approach to this problem? please help. thanks!!
2
3620
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 would like the user to be able to start filling in the form, then get to one of the dropdown lists (ex: Service Type) and realize that the dropdown list does not contain the entry that they need. So next to the Service Type drop down list is a...
5
2238
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 that it would bring back all attachments at all companies or all locations at a company? Thank you, Rob. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not IsPostBack Then
2
12353
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 users need not enter values in all the controls. they can leave the textbox blank, and select values from one drop down, or any other combinations. I am trying to pass values with the help of session variables. But I have multiple if else...
3
2404
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 down's for parameter selection, a 'Search' button and a grid that displays the results (the results contain links to 'Details' page with query string params). The 'Details' Page allows user to see detailed information on the selected product.
19
9074
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 to pass those values, which come from the drop down box, to the next page. The next page should then simply look like this:
1
2351
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 data (box description etc), and a subform for entering details on each file that's in the box (type, subtype etc). The subform is in a datasheet form, with one record on each row. Some of the subform fields are filled in using drop-downs,...
2
1789
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 code that does this. I have left out the portion that connects to my server and the query, but this should be enough to show what I am doing. Basically it is a web page that queries SMS for clients in a certain collection, then outputs the name...
4
1517
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 dropdown list is not tha what i hadve selected(coz it do not support viewstates). is there any method to retrive the values back in drop down. for text i m usoing like this. <tr> <td align="right" > Name : </td> <td><input type=text...
0
8421
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8325
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8844
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8742
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8518
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7354
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.