xhtml typo
[phpmyadmin/crack.git] / libraries / indexes.js
blob6b02e5f394b9fbc9eb704410f06e36efcae1f7d9
1 /* $Id$ */
4 /**
5  * Ensures a value submitted in a form is numeric and is in a range
6  *
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
11  *
12  * @return  boolean  whether a valid number has been submitted or not
13  */
14 function checkFormElementInRange(theForm, theFieldName, min, max)
16     var theField         = theForm.elements[theFieldName];
17     var val              = parseInt(theField.value);
19     if (typeof(min) == 'undefined') {
20         min = 0;
21     }
22     if (typeof(max) == 'undefined') {
23         max = Number.MAX_VALUE;
24     }
26     // It's not a number
27     if (isNaN(val)) {
28         theField.select();
29         alert(errorMsg1);
30         theField.focus();
31         return false;
32     }
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(val + errorMsg2);
37         theField.focus();
38         return false;
39     }
40     // It's a valid number
41     else {
42         theField.value = val;
43     }
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'
52  *
53  * @return  boolean  false if there is no index form, true else
54  */
55 function checkIndexName()
57     if (typeof(document.forms['index_frm']) == 'undefined') {
58         return false;
59     }
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;
70         }
71     }
73     // Other cases
74     else {
75         if (the_idx_name.value == 'PRIMARY') {
76             document.forms['index_frm'].elements['index'].value = '';
77         }
78         if (typeof(the_idx_name.disabled) != 'undefined') {
79             document.forms['index_frm'].elements['index'].disabled = false;
80         }
81     }
83     return true;
84 } // end of the 'checkIndexName()' function
87 onload = checkIndexName;