home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / phpMyAdmin / js / indexes.js < prev    next >
Encoding:
JavaScript  |  2008-06-23  |  2.5 KB  |  92 lines

  1. /* vim: set expandtab sw=4 ts=4 sts=4: */
  2. /**
  3.  * function used for index manipulation pages
  4.  *
  5.  * @version $Id: indexes.js 10142 2007-03-20 10:32:13Z cybot_tm $
  6.  */
  7.  
  8. /**
  9.  * Ensures a value submitted in a form is numeric and is in a range
  10.  *
  11.  * @param   object   the form
  12.  * @param   string   the name of the form field to check
  13.  * @param   integer  the minimum authorized value
  14.  * @param   integer  the maximum authorized value
  15.  *
  16.  * @return  boolean  whether a valid number has been submitted or not
  17.  */
  18. function checkFormElementInRange(theForm, theFieldName, message, min, max)
  19. {
  20.     var theField         = theForm.elements[theFieldName];
  21.     var val              = parseInt(theField.value);
  22.  
  23.     if (typeof(min) == 'undefined') {
  24.         min = 0;
  25.     }
  26.     if (typeof(max) == 'undefined') {
  27.         max = Number.MAX_VALUE;
  28.     }
  29.  
  30.     // It's not a number
  31.     if (isNaN(val)) {
  32.         theField.select();
  33.         alert(errorMsg1);
  34.         theField.focus();
  35.         return false;
  36.     }
  37.     // It's a number but it is not between min and max
  38.     else if (val < min || val > max) {
  39.         theField.select();
  40.         alert(message.replace('%d', val));
  41.         theField.focus();
  42.         return false;
  43.     }
  44.     // It's a valid number
  45.     else {
  46.         theField.value = val;
  47.     }
  48.  
  49.     return true;
  50. } // end of the 'checkFormElementInRange()' function
  51.  
  52.  
  53. /**
  54.  * Ensures indexes names are valid according to their type and, for a primary
  55.  * key, lock index name to 'PRIMARY'
  56.  *
  57.  * @return  boolean  false if there is no index form, true else
  58.  */
  59. function checkIndexName()
  60. {
  61.     if (typeof(document.forms['index_frm']) == 'undefined') {
  62.         return false;
  63.     }
  64.  
  65.     // Gets the elements pointers
  66.     var the_idx_name = document.forms['index_frm'].elements['index'];
  67.     var the_idx_type = document.forms['index_frm'].elements['index_type'];
  68.  
  69.     // Index is a primary key
  70.     if (the_idx_type.options[0].value == 'PRIMARY' && the_idx_type.options[0].selected) {
  71.         document.forms['index_frm'].elements['index'].value = 'PRIMARY';
  72.         if (typeof(the_idx_name.disabled) != 'undefined') {
  73.             document.forms['index_frm'].elements['index'].disabled = true;
  74.         }
  75.     }
  76.  
  77.     // Other cases
  78.     else {
  79.         if (the_idx_name.value == 'PRIMARY') {
  80.             document.forms['index_frm'].elements['index'].value = '';
  81.         }
  82.         if (typeof(the_idx_name.disabled) != 'undefined') {
  83.             document.forms['index_frm'].elements['index'].disabled = false;
  84.         }
  85.     }
  86.  
  87.     return true;
  88. } // end of the 'checkIndexName()' function
  89.  
  90.  
  91. onload = checkIndexName;
  92.