Code Igniter: How do I add these anchor tags to a dropdown menu?
This is probably pretty simple but I am new to this.
All I want to do is put some of the current links I have working inside a dropdown menu.
Here are the working links I would like to display in a dropdown:
<p>
<?=anchor('tasks/AddTask', 'Add a Task')?>
<?=anchor('tasks', 'All Tasks')?>
<?=anchor('tasks/mjh', 'Mike')?>
<?=anchor('tasks/ejm', 'Ed')?>
<?=anchor('tasks/fjb', 'Jan')?>
<?=anchor('tasks/ctk', 'Colin')?>
<?=anchor('tasks/cgb', 'Cindy')?>
</p>
The following does not seem to work:
<form>
<p>
Change View:
<select>
<option value="tasks">All Tasks</option>
<option value="tasks/mjh">Mike</option>
<option value="tasks/ejm">Ed</option>
</select>
<input type="submit" value="Go">
</p>
</form>
Or:
<form>
<p>开发者_运维问答
Change View:
<select>
<option><?=anchor('tasks', 'All Tasks')?></option>
<option><?=anchor('tasks/mjh', 'Mike')?></option>
<option><?=anchor('tasks/ejm', 'Ed')?></option>
</select>
<input type="submit" value="Go">
</p>
</form>
Thank you.
Anchor tags won't work as they create full hyperlinks, and not just the URL. The following should work:
<select id="my_links" name="my_links">
<option value="<?php echo site_url('some/path'); ?>"><?php echo site_url('some/path'); ?</option>
</select>
Then you could use a bit of Javacsript to redirect the browser to the specified URL.
See here:
using href links inside <option> tag
It uses a bit of javascript and plain old HTML rather than the CodeIgniter helper, but should point you in the right direction.
You could just use javascript.
<select onchange="document.location=this.options[this.selectedIndex].value;">
<option value="<?php echo site_url('the/path'); ?>">All Tasks</option>
<option value="<?php echo site_url('the/path'); ?>">Mike</option>
<option value="<?php echo site_url('the/path'); ?>">Ed</option>
</select>
精彩评论