Hey guys,

I want to have sth. like this here:

Select a page

foo
bar
blub

I realized that with a little javascript code:

$("#edit-jump-goto option:first").before("<option selected=\"selected\">Select a category</option><option></option>");

But that's bullshit cause if I click on the placeholder the jump.module wants to go to myurl.com/.

What can I do here?

yannick

Comments

pontus_nilsson’s picture

You could add a option with the value "0" to the select list and in when you redirect you check for values that are not 0:

This code should go in to a .js file added to your themes .info file.

Drupal.behaviors.shortcutMenu = function(context) {
  var option = $('<option />').text(Drupal.t('- Select -')).attr('value', '0')[0];
  $('#edit-jump-goto select:not(.shortcutmenu-processed)', context)
    .addClass('shortcutmenu-processed')
    .prepend(option).val('0')
    .bind('change click', function() {
      var selected = $('option:selected', this);
      if ($(selected).attr('value') !== '0') {
        window.location = selected.val();
      }
    });
}

This code will also trigger a redirect when selecting one of the values. To remove the Go button you could add some css to your theme. html.js .jump-quickly input { display:none; }

I use the code above for external links. If your links are internal (node/10) then you could add something like:
window.location = Drupal.settings.basePath + selected.val();

hessam61’s picture

Hey,

Thanks for this code, but it didn't work for me. Am I supposed to change ".shortcutmenu-processed" ? Is this in your markup? Also I am using internal pages, and as you suggested I replace the line you mentioned. Here's my code that I am adding to a js file in drupal 6.19:

Drupal.behaviors.shortcutMenu = function(context) {
  var option = $('<option />').text(Drupal.t('Select')).attr('value', '0')[0];
  $('#edit-jump-goto select:not(.shortcutmenu-processed)', context)
    .addClass('shortcutmenu-processed')
    .prepend(option).val('0')
    .bind('change click', function() {
      var selected = $('option:selected', this);
      if ($(selected).attr('value') !== '0') {
        window.location = Drupal.settings.basePath + selected.val();
      }
    });
}

Thanks,

pontus_nilsson’s picture

It is this line you will need to change:
$('#edit-jump-goto select:not(.shortcutmenu-processed)', context)

where #edit-jump-goto is the ID for the selector the shortcut menu you want this script to work on.

Later after i replied to you I found the module Special Menu Items which can create placeholder items in menus.

hessam61’s picture

Thanks for replying. The div id in my markup happens to be the same as yours. I solve the problem with this jQuery:

$(document).ready(function() {
                $('#edit-jump-goto').prepend('<option value="0" selected="selected">Select</option>');
});
yannickoo’s picture

Similar to my code ;)

$("#edit-jump-goto option:first").before("<option selected=\"selected\">Select a category</option><option></option>");

marcp’s picture

Version: 6.x-1.x-dev » 6.x-2.x-dev
Status: Active » Closed (duplicate)

This is now a duplicate of #270924: Jump without "Go" Button which will incorporate something similar in the 2.x branch.

doublejosh’s picture

Is this planned to allow for Special Menu items that end up as OptGroups or non-functional options, etc.?

I have some code to contribute, but want to match up to share best :)