sorry, wrong version checked in
[phpmyadmin/arisferyanto.git] / libraries / indexes.js
blob8493881d63f6feaf12b3a1be9eb18cf4fd1ddb83
1 /* $Id$ */
4 /**
5 * Ensures a value submitted in a form is numeric and is in a range
7 * @param object the form
8 * @param string the name of the form field to check
9 * @param integer the minimum authorized value
10 * @param integer the maximum authorized value
12 * @return boolean whether a valid number has been submitted or not
14 function checkFormElementInRange(theForm, theFieldName, message, min, max)
16 var theField = theForm.elements[theFieldName];
17 var val = parseInt(theField.value);
19 if (typeof(min) == 'undefined') {
20 min = 0;
22 if (typeof(max) == 'undefined') {
23 max = Number.MAX_VALUE;
26 // It's not a number
27 if (isNaN(val)) {
28 theField.select();
29 alert(errorMsg1);
30 theField.focus();
31 return false;
33 // It's a number but it is not between min and max
34 else if (val < min || val > max) {
35 theField.select();
36 alert(message.replace('%d', val));
37 theField.focus();
38 return false;
40 // It's a valid number
41 else {
42 theField.value = val;
45 return true;
46 } // end of the 'checkFormElementInRange()' function
49 /**
50 * Ensures indexes names are valid according to their type and, for a primary
51 * key, lock index name to 'PRIMARY'
53 * @return boolean false if there is no index form, true else
55 function checkIndexName()
57 if (typeof(document.forms['index_frm']) == 'undefined') {
58 return false;
61 // Gets the elements pointers
62 var the_idx_name = document.forms['index_frm'].elements['index'];
63 var the_idx_type = document.forms['index_frm'].elements['index_type'];
65 // Index is a primary key
66 if (the_idx_type.options[0].value == 'PRIMARY' && the_idx_type.options[0].selected) {
67 document.forms['index_frm'].elements['index'].value = 'PRIMARY';
68 if (typeof(the_idx_name.disabled) != 'undefined') {
69 document.forms['index_frm'].elements['index'].disabled = true;
73 // Other cases
74 else {
75 if (the_idx_name.value == 'PRIMARY') {
76 document.forms['index_frm'].elements['index'].value = '';
78 if (typeof(the_idx_name.disabled) != 'undefined') {
79 document.forms['index_frm'].elements['index'].disabled = false;
83 return true;
84 } // end of the 'checkIndexName()' function
87 onload = checkIndexName;