I am trying to build a simple calculator module or I should say I am trying to learn the principals required to make a Drupal 7 math/calculator module that simply takes users inputs (form(numbers)) and dose some math on them and then displays the results on the same page with out a page refresh. dont need forme validation because not going to db; just calculating and displaying results.

I have been able to get hook_menu to work and build a path to js script function to work in my .module file:

<?php

/**
 * Implements hook_menu().
 */
function calculator_jquery_menu() {
  $items['calculator_jquery'] = array(
    'title' => "Craig's jquery calculator module",
    'description' => 'Demonstration of various JavaScript utilities',
    'page callback' => 'calculator_jquery_p',
    'access callback' => TRUE,
  );
  return $items;
}

function calculator_jquery_p(){
	 // Set the path to our script.
  $script = drupal_get_path('module', 'calculator_jquery') . '/calculator_jquery.js';

  // Include a JavaScript file.
  $js = drupal_add_js($script);

 $build = array(
 //  '#type' => 'markup',
 //  '#markup' => '<p>This is an examples page.</p>',
  );

  return $build;
}

My .js file is working:

jQuery(document).ready(function () {
//var text = jQuery('h1').text();
alert(1);
//<input type="checkbox" class="option" value="200" /> Name<br />;
//<input type="CHECKBOX" name="check1" value="yes" checked>;
//document.write('eee');
});

Sense I don't need a form validation I would like to use js forms not the Drupal form api. I have tried the following code in the js file with no luck as a simple test case using checkbox:
<input type="checkbox" class="option" value="200" /> Name<br />;
the check box is not recognized by Drupal.
Dose any body have a suggestion how I can get this to work? or a good code resource/strategy to making this type of module? I am confused with how to write js code in drupal that is self running; all info for js in Drupal that I have found is hooking into the csm content/frame work. I would think that there is value to making some modules that just perform simple stuff(calculators, ect) with out hooking in to something else.

Thank you for any suggestions.

Comments

Aqyznm’s picture

The most difficult task for me was to create a calculator on Drupal and attach it to the goods. I did this for a long time and suffered until I found stepFORM and it made my work much easier.