Click to See Complete Forum and Search --> : <select value=1 default=on> ??


hammerslane
12-17-2003, 09:46 AM
hiya folks

i know the code in the subject isn't right.
i'm going to explain my simple problem, extremely thoroughly, just so you know exactly what i'm trying to do.

i have three pages.

1.html
2.php
3.php

1.html: define $option for the first time
there is quite simply a page with four links;<a href="2.php?option=1">
<a href="2.php?option=2">
<a href="2.php?option=3">
<a href="2.php?option=4">

2.php: confirm the value of $option, it should display whatever link was clicked on 1.html
there is a simple form, a drop down list and a submit button.<form action="3.php">
<select name="option" code should go here??>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</form>

3.php
<?
echo $option;
?>

in a nutshell, i basically want a drop down box to display a value which has been defined on a previous page. i thought that maybe the code in the subject was on the right lines... or maybe it's just not possible to do using just html.

many thanks

Paul Jr
12-17-2003, 05:26 PM
Originally posted by hammerslane
or maybe it's just not possible to do using just html.

Correct. I am quite sure you can do this with PHP, and maybe even JS.

PunkSktBrdr01
12-17-2003, 07:45 PM
I think you have to add "default" to the correct option, like:

<form action="3.php">
<select name="option">
<option value="1">1</option>
<option value="2" default>2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</form>


Could be a different word though, like "selected".

IncaWarrior
12-17-2003, 09:29 PM
yeah if you put in selected -no quotes or anything - then it selects that one

pyro
12-17-2003, 09:31 PM
...but, if you are using XHTML or ever plan to, you should use selected="selected", as XHTML can not have empty attributes. It's good practice to do so.

fredmv
12-17-2003, 09:31 PM
If you're using an XHTML DOCTYPE you'll need to do:<option selected="selected">foo</option>Since attribute minimization isn't allowed in XHTML.

Edited: You beat me to it Ryan... :D

Paul Jr
12-17-2003, 10:27 PM
Mmm, apparently I misunderstood what he was trying to do... :rolleyes:

pyro
12-17-2003, 10:37 PM
Originally posted by fredmv
Edited: You beat me to it Ryan... :D Yep, but barely... :p

hammerslane
12-18-2003, 02:51 AM
thanks very much folks, incase you're interested, here's the final code i used<select name="option">

<option <? if ($option=="option") { echo "selected=selected"; } ?> value="1">1</option>

<option <? if ($option=="option") { echo "selected=selected"; } ?> value="2">2</option>

<option <? if ($option=="option") { echo "selected=selected"; } ?> value="3">3</option>

<option <? if ($option=="option") { echo "selected=selected"; } ?> value="4">4</option>

</select>

pyro
12-18-2003, 08:09 AM
Didn't like fredmv's and my suggestion, eh? Ah well, we tried...

hammerslane
12-18-2003, 08:23 AM
ah yes... see above edit :cool:
thanks once again

pyro
12-18-2003, 08:27 AM
Much better... ;)

fredmv
12-18-2003, 08:31 AM
Good choice. ;)

hammerslane
12-18-2003, 08:32 AM
do some browser types not like the 'select' sitting there on its own? what if i never plan to use xhtml on the site?
i'm not arguing... just quite interested.
does html on its own always accept the 'select' on its own, in all browsers?