javascript

Drupal URL Arguments in Javascript

Sometimes a prerequisite to getting a burrito for lunch involves using Drupal URL arguments in Javascript. So for example, say you had a URL like this:

http://www.tylerfrankenstein.com/chicken/burrito/combo

You can add code like this to your module:

function my_module_init () {
  drupal_add_js(array('arg' => arg()),'setting');
}

And finally you can use code like this in Javascript to use the Drupal URL arguments:

JavaScript Date Time YYYY MM DD HH MM SS

Robot: "What time is it JavaScript, buddy? And when you answer, it better be in the format of 'YYYY-MM-DD HH:MM:SS' in 24 hour format with preceeding zeros on the month, day, hour, minute and second, or else!"

Me: "Relax big guy, just call this function, friend."

JavaScript Regular Expressions in Internet Explorer

So today Internet Explorer again decided to be totally awesome...

I have a simple javascript regular expression that extracts the Drupal 'page' variable from a link that was clicked:

<a href="/code?page=1" id="tf_example_link">next page</a>
$('a#tf_example_link').click(function () {
  var page = /[\?&]+page=([0-9]+)[\?&]?/($(this).attr('href'));
  alert(page); // alert output: 1
});

This works in all browsers, except....... drum roll.............. Internet Explorer! Surprised? Probably not.

Drupal - Post Data via Ajax to PHP Menu Callback with JQuery and JSON

Drupal 7

I found this solid example for Drupal 7.

http://www.computerminds.co.uk/drupal-code/make-link-use-ajax-drupal-7-its-easy

The code for D7 is much more elegant, there are some great new features in D7 to make this stuff easier.

Drupal 6

Put this PHP code inside your module, e.g. sites/all/modules/my_module/my_module.module

Subscribe to RSS - javascript