Forum Moderators: coopster

Message Too Old, No Replies

PHP Drop Down List Question

         

decadre

6:24 pm on Apr 8, 2006 (gmt 0)

10+ Year Member



Ok, here is the code I have. Array has been shortened.

<fieldset><legend>Search for Collection Nodes</legend>
<form action="eq2Collect.php" method="post">
<?php
$zones = array (1 => 'Antonica', 'Barren Sky', 'Blackburrow')
echo '<select name="zoneSearch">';
foreach ($zones as $key => $value) {
echo "<option value=\"$key\"> $value </option>\n";
}
echo '</select>';
?>
<input type="submit" name="submitSearch" value="Search Zone for Nodes" />
<input type="hidden" name="submittedSearch" value="TRUE" />
</form>
</fieldset><br />
Ok, so I get the drop down box, and the button.

How do I go about getting text to appear somewhere on my page that would say something like;

"You selected zone Commonlands"

when the submit button is pressed? Essentially, I don't know how to get the item in the drop down list that has been selected before the submit button is pressed.

I've tried many variations of;

if(isset($_POST['submittedSearch'])){
echo $_get['zoneSearch'];
}

Anyango

7:35 pm on Apr 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to Webmasterworld, decadre!

as your Form has method=POST therefore

echo $_get['zoneSearch'];

wont work

try this

echo $_POST['zoneSearch'];

decadre

11:07 pm on Apr 8, 2006 (gmt 0)

10+ Year Member



thanks for replying. I'm finally getting somewhere. However, doing this;

echo $_POST['zoneSearch'];

simply causes the index number to whatever selection in this list to be outputted(echoed) onto the web page.

I'm going to try to figure it out, but in case I have no luck I'd thought that I would reply here first.

decadre

11:18 pm on Apr 8, 2006 (gmt 0)

10+ Year Member



I did this, and it works;

$zones[$_POST['zoneSearch']]

Anyango

9:30 am on Apr 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad you Figured it out :)