0

I am using Joomla 3.6.5 and I want to make a drop down list in a page of my web site Joomla.

my scenario is:

I have 48 states, the user have to click his state in the list and then he will be redirect in other page which describe the content concerning his state.

After looking in the web, I find the extension SobiPro but it has only 30 link not more.

I am new in Joomla and I don't know how to do that.

Please help me for solve my confusion.

Nidhi
  • 1,529
  • 18
  • 28

1 Answers1

1

Here's a general solution that you could use on any site: https://codepen.io/panchroma/pen/pPQbxg

I have it working well on a Joomla site.

Add this javascript to your page

<script language="JavaScript" type="text/javascript">
    function ChangeUrl(form) {
        if (form.State.selectedIndex != 0) {
            var url;
            url = form.State.options[form.State.selectedIndex].value;
            window.open(url, '_self');
        }
    }
</script>

Then manually build up your form

<form>
    <select name="State" onchange="ChangeUrl(this.form)">
        <option selected="selected" value="">Choose you State</option>
        <option value="#state1">state1</option>
        <option value="#state2">state2</option>
        <option value="#state3">state3</option>
    </select>
</form>  

Hope this helps!

David Taiaroa
  • 25,157
  • 7
  • 62
  • 50
  • Which page I should add this script ? – Moon Nydel May 21 '17 at 11:43
  • @MoonNydel, you want to add the script either to the page where you'll have the list of states that your visitors select from, or to site wide javascript file if your template uses one. Do you know how to do either of these? – David Taiaroa May 21 '17 at 12:48
  • I want to add the script only to the page where I will have the list of states. I am using _SP Page Builder_ which is empty now because this page has to contain only the drop down list. I don't know exactly where to add the script unfortunately – Moon Nydel May 21 '17 at 14:05
  • If you have a pro version of SP Page Builder you could experiment using their raw html addon. If not the following will work. Extensions > Module > New > Custom, then depending on your editor switch to the code or source view and paste in the javascript above. Publish the module either on every page or just the one page where you need it, you will need to select a module position in your template. By default, Joomla editors often strip javascript from html, if you suspect this is happening Google ' Joomla text filtering' + the name of your text editor. Let me know if you need more help – David Taiaroa May 22 '17 at 02:51
  • Thank you very much for helping me, that's very kind. Well when I pass the javascript in source view of my new custom module, it does not consider the script, the editor erases the code when I click to register. – Moon Nydel May 22 '17 at 09:19
  • What editor are you using? It will be listed under Users > Manage, select the user then look under the Basic Settings tab > Editor – David Taiaroa May 22 '17 at 12:01
  • The editor is on default setting (probably TinyMCE editor). – Moon Nydel May 22 '17 at 17:09
  • To stop Tiny MCE from stripping javascript, go to Extensions -> Plug-in Manager -> Editor – TinyMCE. Open it, then in the “Prohibited Elements” area remove 'script,', leaving just 'applet,iframe' – David Taiaroa May 22 '17 at 22:38
  • I remove script from "Prohibited Elements" and I recreate my new custom module, now it register the script but the script doesn't do anything; the drop down I create in my _SP Page Builder_ via HTML addon exists but when I click the state nothing is happening. I noticed that the script is registered with additional comments like this : – Moon Nydel May 23 '17 at 13:39
  • `` – Moon Nydel May 23 '17 at 13:49
  • The additional comments you mention should be OK. Do you know how to use web inspector to check for errors when you select a dropdown on the form? – David Taiaroa May 23 '17 at 15:59
  • I have this error
    is not recognized! above the dropdown code
    – Moon Nydel May 24 '17 at 09:32
  • Hi @MoonNydel, sorry I'm not sure what could be causing your error. Here's another idea that I've tested, maybe this will work for you. Keep your module published site-wide, you don't need to select a position though. Then go to your page in SP Page Builder, choose 'Addon' then Joomla module. You'll see an option to select the module, use this to locate the module which contains your form. Select your module, save, and see what happens ;) – David Taiaroa May 30 '17 at 01:38