3

I would like to have a tag search button in Tumblr by selection using the select option but I am not sure how to insert the onclick event using Tumblr's {text:Search Label}.

form action = "">
   <select name = "Cities">
       <option value="----">--Select--</option>
       <option value="roma">Roma</option>
       <option value="torino">Torino</option>
       <option value="milan">Milan</option>
   </select>

Anyone here can help? Thanks.

dg99
  • 5,456
  • 3
  • 37
  • 49
EJKoya
  • 41
  • 3
  • Have a look at this: http://stackoverflow.com/questions/2000656/using-href-links-inside-option-tag – lharby Jul 18 '14 at 13:55
  • I have a jquery solution mixing the answer above and your code. Is that any use? Most tumblr themes have jquery linked, but not all, if not it's very easy to link it. – lharby Jul 18 '14 at 14:10

1 Answers1

2

Well here is my code: http://jsfiddle.net/htWW6/

This is the script:

  $(document).ready(function(){
     $('select').bind('change',function(){
     var loc = $(this).val();
     location = "/tagged/" + loc;
   });
});

This is jquery, so if your theme currently has this installed (many do) then that code should work off the shelf. If not then it is very easy to add jquery, but if you need a pure JS solution, I cannot help with that. Although the other answer does offer some insight.

lharby
  • 3,057
  • 5
  • 24
  • 56
  • Hi lharby, Yes, this works fine but what if I need to use a button? – EJKoya Jul 21 '14 at 09:11
  • That should be easier to code, if I get some time I will try and type something out later. – lharby Jul 21 '14 at 09:36
  • Hey do you really want a button element? Or something that looks like a button. It would be better to do this with an anchor tag and style it like a button, I believe, much easier. Generally an html button might be a Submit or Reset on a form but would be used to send lots of bits of information rather than a single link. It can be done though with js/jquery, but I think an anchor makes more sense. – lharby Jul 22 '14 at 08:16
  • You got a point there. Sure, it'll be nice if you can help me on that lharby – EJKoya Jul 25 '14 at 02:22