views:

264

answers:

4

I'm trying to anchor a div with an option tag but it doesn't work, what´s wrong with my code? Here´s the anchor snippet

<select>
        <option value="#b1">1 test</option>
</select>
<br />
<br />
<br />
<br />
<br />
<br />
<div id="b1">Testing!</div>
+1  A: 

You'll need to add an onchange handler to the select element.

function scrollTo(elmt) { $(elmt.options[elmt.selectedIndex].value).scrollTo(); //With Prototype }

To your select, add onchange=scrollTo()

sonofdelphi
will this work with option value and div id?
blub
yeah, it should. i assume you are OK with using Javascript....or do u want a pure HTML solution?
sonofdelphi
Javascript is ok if the code works on ie6 too.About the code, I've just tried it with that function but it didnt work, ill post the code I tried as an answer.
blub
Bet you ignored the bit about needing to use Prototype
David Dorward
nope, I tried this with prototype
blub
+3  A: 

See Navigational pulldown menus in HTML (especially the part about how they are horrible and you should use a normal set of links instead)

David Dorward
thanks for the link but I couldn't find any example with id's on the same page (instead they´re links to other pages)
blub
A URL is a URL. It doesn't matter if the new one is on the same page or not.
David Dorward
A: 

I've tried sonofdelphis solution with no success, here's the code:

<script>
function scrollTo(elmt) { $(elmt.options[elmt.selectedIndex].value).scrollTo();}
</script>

<label>Choose your destiny:</label><br />
<select onchange="scrollTo();">
<option value="#b1">1. blub</option>
</select>
<br /><br /><br /><br /><br /><br /><br /><br />
<div id="b1">testing</div>
blub
Please don't comment on answers by posting **answers**!
David Dorward
Make it onchange = "scrollTo(this)". If you want it this to work, you will need to include prototype.js as well...
sonofdelphi
A: 

Even if I get some code to work I'm still wondering if it'll work on older browsers like ie6

blub
Please don't comment on answers by posting **answers**!
David Dorward