4

I'm sure this shouldn't be so hard!

I've been struggling with facebook's javascript: I need to redirect to a URL based on the value in a select drop down menu, something like:

<form name="cityselect">
    <select name="menu" onChange="location=document.cityselect.menu.options[document.cityselect.menu.selectedIndex].value;" value="GO">
        <option value="http://www.leeds.html">Leeds</option>
        <option value="http://www.manchester.html">Manchester</option>
    </select>
</form>

Can anybody help me get this working? I've had good look though the facebook dev forum and docs but either don't understand what needed or can't find the answer!

2 Answers 2

18

Try {} this.options also your urls are mistyped. http://www.leeds.html should be http://www.leeds.com , not sure if that is related but just wanted to point that out just in case.


<form name="cityselect">
    <select name="menu" onChange="window.document.location.href=this.options[this.selectedIndex].value;" value="GO">
        <option selected="selected">Select One</option>
        <option value="http://www.leeds.com">Leeds</option>
        <option value="http://www.manchester.com">Manchester</option>
    </select>
</form>

Parent Frame:

<form name="cityselect">
    <select name="menu" onChange="top.location.href=this.options[this.selectedIndex].value;" value="GO">
        <option selected="selected">Select One</option>
        <option value="http://www.leeds.com">Leeds</option>
        <option value="http://www.manchester.com">Manchester</option>
    </select>
</form>
2
  • 1
    Works perfectly, thank you! The URL was mistyped when I slimmed the code down for brevity, working too late again.. So did my method not work because it was in an iFrame or because it was in a Facebook iFrame? Anyhow, thanks again, really appreciate the help
    – matt_50
    Commented Nov 4, 2011 at 8:16
  • well i had to rewrite the who thing, javascript could not find name menu with out a name on the form. I just used this.selectedIndex instead. I posted one for iframe and one for stand alone. Commented Nov 4, 2011 at 16:28
-1

how to remember selection after redirect.

for example

let us suppose there are many city name in drop down. when i select city name in drop down then relevant page should appear on website and selection of current city should remain on redirected page until selection not changed

all redirect on same domain with subdomain all sub domain layout same dropdown will be available on all pages of website.

1
  • This is a very old post which has been answered. Also your post doesn't answer the question, it seems to be asking another question. If you are answering the question, you need to provide a technical solution - if this is a separate question, please post as a separate question as this is a very old post.
    – smackenzie
    Commented Oct 26, 2017 at 22:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.