By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,733 Members | 846 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,733 IT Pros & Developers. It's quick & easy.

Assigning values back to drop down box

P: n/a
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
Share this Question
Share on Google+
7 Replies


P: n/a
"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

P: n/a
>...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

P: n/a
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

P: n/a
"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

P: n/a
"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

P: n/a
"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.