source: TI03-DataExtractor/branches/old_stuff/dx_badc/js_funcs.py @ 793

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI03-DataExtractor/branches/old_stuff/dx_badc/js_funcs.py@793
Revision 793, 2.7 KB checked in by astephen, 13 years ago (diff)

Put all the old code in the old_stuff branch.

Line 
1"""
2js_funcs.py
3===========
4
5Holder module for Javascript functions that will be inserted into the header
6of relevant web pages for checking purposes.
7
8"""
9
10
11js_documentation_for_better_funcs="""
12While there are many ways different browsers can reflect the selected value, one which works on different browsers is:
13
14var n = obj.selectedIndex;    // Which menu item is selected
15var val = obj[n].text;        // Return string value of menu item
16
17To set the value, if you know the correct .selectedIndex, you can just set that. If you do not, you need to iterate over the various values:
18
19for (var i = 0; i < obj.length; ++i)
20  if (obj[i].text == 'Second')
21    obj.selectedIndex = i;
22
23If your HTML also sets value attributes for the different menu items, you can read and set the .value attributes for the various option objects.
24
25Setting an event handler is trickier than the other form objects, since different browsers trigger different events; Internet Explorer will trigger an onclick event for the <select></select>, Safari will trigger both onclick and onchange events for the , and Mozilla will trigger an onchange event for the as well as an onclick event for the <option></option> which was selectted.
26
27One way to handle the event in a cross-browser manner is to set an onclick event handler on the outer select, such as:
28
29<select name="menuchoice" onclick="didselect ()">
30  <option>First</option>
31  <option>Second</option>
32  <option>Third</option>
33</select>
34
35You then need to make sure your current object is the same for all browsers:
36
37while (obj && obj.tagName != 'SELECT')
38  obj = obj.parentNode;
39
40All browsers will ignore the return value of the event handler.
41
42"""
43
44js_checkDateOrder="""
45
46function checkDateOrder(dateField) {
47    startDate=new Array(extract_info.start_year.value, extract_info.start_month.value,
48                        extract_info.start_day.value, extract_info.start_hour.value);
49    endDate=new Array(extract_info.end_year.value, extract_info.end_month.value,
50                      extract_info.end_day.value, extract_info.end_hour.value);
51
52    for (i=0; i<startDate.length; ++i) {
53        currentStart=startDate[i];
54        currentEnd=endDate[i];
55
56        if (currentStart > currentEnd) {
57            if (dateField=="end") {
58                extract_info.start_year.value=endDate[0];
59                extract_info.start_month.value=endDate[1];
60                extract_info.start_day.value=endDate[2];
61                extract_info.start_hour.value=endDate[3];
62            } else {
63                extract_info.end_year.value=startDate[0];
64                extract_info.end_month.value=startDate[1];
65                extract_info.end_day.value=startDate[2];
66                extract_info.end_hour.value=startDate[3];
67            }
68        }
69    }
70}
71
72"""
Note: See TracBrowser for help on using the repository browser.