<select value=1 default=on> ??

liunx

Guest
hiya folks<br />
<br />
i know the code in the subject isn't right.<br />
i'm going to explain my simple problem, extremely thoroughly, just so you know exactly what i'm trying to do.<br />
<br />
i have three pages.<br />
<br />
1.html<br />
2.php<br />
3.php<br />
<br />
1.html: define $option for the first time<br />
there is quite simply a page with four links;<a href=http://www.webdeveloper.com/forum/archive/index.php/"2.php?option=1"><br />
<a href=http://www.webdeveloper.com/forum/archive/index.php/"2.php?option=2"><br />
<a href=http://www.webdeveloper.com/forum/archive/index.php/"2.php?option=3"><br />
<a href=http://www.webdeveloper.com/forum/archive/index.php/"2.php?option=4"><br />
<br />
2.php: confirm the value of $option, it should display whatever link was clicked on 1.html<br />
there is a simple form, a drop down list and a submit button.<form action="3.php"><br />
<select name="option" code should go here??><br />
<option value="1">1</option><br />
<option value="2">2</option><br />
<option value="3">3</option><br />
<option value="4">4</option><br />
</select><br />
</form><br />
<br />
3.php<br />
<?<br />
echo $option;<br />
?><br />
<br />
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.<br />
<br />
many thanks<!--content-->Originally posted by hammerslane <br />
or maybe it's just not possible to do using just html. <br />
<br />
Correct. I am quite sure you can do this with PHP, and maybe even JS.<!--content-->I think you have to add "default" to the correct option, like:<br />
<br />
<form action="3.php"><br />
<select name="option"><br />
<option value="1">1</option><br />
<option value="2" default>2</option><br />
<option value="3">3</option><br />
<option value="4">4</option><br />
</select><br />
</form><br />
<br />
<br />
Could be a different word though, like "selected".<!--content-->yeah if you put in selected -no quotes or anything - then it selects that one<!--content-->...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.<!--content-->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.<br />
<br />
Edited: You beat me to it Ryan... :D<!--content-->Mmm, apparently I misunderstood what he was trying to do... :rolleyes:<!--content-->Originally posted by fredmv <br />
Edited: You beat me to it Ryan... :D Yep, but barely... :p<!--content-->thanks very much folks, incase you're interested, here's the final code i used<select name="option"><br />
<br />
<option <? if ($option=="option") { echo "selected=selected"; } ?> value="1">1</option><br />
<br />
<option <? if ($option=="option") { echo "selected=selected"; } ?> value="2">2</option><br />
<br />
<option <? if ($option=="option") { echo "selected=selected"; } ?> value="3">3</option><br />
<br />
<option <? if ($option=="option") { echo "selected=selected"; } ?> value="4">4</option><br />
<br />
</select><!--content-->Didn't like fredmv's and my suggestion, eh? Ah well, we tried...<!--content-->ah yes... see above edit :cool:<br />
thanks once again<!--content-->Much better... ;)<!--content-->Good choice. ;)<!--content-->do some browser types not like the 'select' sitting there on its own? what if i never plan to use xhtml on the site?<br />
i'm not arguing... just quite interested.<br />
does html on its own always accept the 'select' on its own, in all browsers?<!--content-->
 
Back
Top