Log in

View Full Version : Select a drop-down option via anchor 'name'



Mighterbump
03-07-2006, 06:37 AM
Is there a way to select a 'option' in a drop-down menu by ways of typing in a anchor name in the URL address bar?

My idea is to have the dropdown menu in with the Dynamic Ajax content (http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm) and change it's content by what option is selected in the dropdown menu.

Example: You type in "http://site.com/index.html#tooth" and it will load up the page with 'tooth' as the "SELECTED" option in the dropdown menu and then rely that to the Ajax for what file to select.

If not are there any other ways of selecting objects when it typed in the url?

djr33
03-07-2006, 07:40 AM
PHP offers a way to do this quite easily.

Depending on the complexity of your plans, you might have to expand this, but for your simple example above, here's the deal:


Assume your url is http://.../index.php?selected=tooth (<<note varied syntax, slightly)

<form ...>
<input type="dropdown" value="<?php //initiates php
$sel = $_GET['selected']; //assigns the 'tooth' (etc) value to the $sel variable.
echo $sel; //prints to html the value of $sel, in this case 'tooth'.
?>">
<more form stuff...>
</form>

the above should simplify down to

<form ...>
<input type="dropdown" value="tooth">
<more form stuff...>
</form>

If it needs to be more complex, then get more into php. It can do if statements, loops, and other things that might help you out. Really depends what you need.