Inky1231
Inky1231

Reputation: 85

Onchange selectbox in Drupal

Hi Ladies and Gentlemen, Where I work is currently transitioning to a site using Drupal 7. We are trying to get a temporary site up and running until our new site is finished. I am a complete newbie to Drupal, but managing ok. Anyway I have a page that has an onchange select box which is supposed to open a PDF file. I am unclear how to make the onchange function work. I have looked on several pages but everything is a little confusing. Here is the code I need to change :

<form name="cataloglinks" action="">

<p class="style2">

<span class="style3">
Other editions of the online DACC catalog are also available:


<select name="cataloglinks-list" size="1" id="cataloglinks-list    onchange="goPage(this.options[this.selectedIndex].value)">"
<option value="." selected="selected">Select an edition</option>
<option value="catalog/catalog08-09.pdf">Catalog for 2008-2009</option>
<option value="catalog/catalog09-10.pdf">Catalog for 2009-2010</option>
<option value="catalog/catalog10-11.pdf">Catalog for 2010-2011</option>
<option value="catalog/catalog11-12.pdf">Catalog for 2011-2012</option>
<option value="catalog/catalog12-13.pdf">Catalog for 2012-2013</option>
<option value="catalog/catalog13-14.pdf">Catalog for 2013-2014</option>

Upvotes: 0

Views: 123

Answers (1)

Aboodred1
Aboodred1

Reputation: 1503

Your issue has nothing to do with Drupal, it might be a HTML tags issue or missing goPage() javascript function.

Try to implement the following code:

<script type="text/javascript">
  function goPage(path) {
      if(path != '') {
          window.location = [location.protocol, '//', location.host, '/'].join('') + path;
      }
  }
</script>

<select name="cataloglinks-list" size="1" id="cataloglinks-list" onchange="goPage(this.options[this.selectedIndex].value);">
    <option value="" selected="selected">Select an edition</option>
    <option value="catalog/catalog08-09.pdf">Catalog for 2008-2009</option>
    <option value="catalog/catalog09-10.pdf">Catalog for 2009-2010</option>
    <option value="catalog/catalog10-11.pdf">Catalog for 2010-2011</option>
    <option value="catalog/catalog11-12.pdf">Catalog for 2011-2012</option>
    <option value="catalog/catalog12-13.pdf">Catalog for 2012-2013</option>
    <option value="catalog/catalog13-14.pdf">Catalog for 2013-2014</option>
</select>

Note: I assumed that catalog folder is in the root directory of your site.

Upvotes: 1

Related Questions