ScotDiddle Posted September 4, 2008 Share Posted September 4, 2008 Hi All, Too bad javascript is necessary to learn and hard to master. Q1: Why doesn't JS executed sequentially ? I have a JS application loop which is supposed to pass vars to PHP via new Image(), then alert the success of the transfer for each of the items in an array. Only the first var gets past to PHP, and while it is doing it's PHP thing, I receive alerts for all of the remaining vars. Q2. Why doesn't JS keep track of var name "i" in for(i=0; i<= someMaxLimit; i++) {} loops. Sounds crazy, I know... I have the aforementioned JS application which has about 13 different "for" loops, each has an alert showing the value of the array item, and the index being processed. ( "i" ). I used "i" for all of them, but the alert for "i" returns a value which is all over the map, but never larger than the largest "someMaxLimit" value. The only way I could get consistant, reliable results was to use: for (a=0; a<=maxValueForA; a++) {} --> b,c,d,e... for (m=0; m<=maxValueForM; m++) {} When I used a unique value for the index in each "for" loop, the alert for the index always returned the value I was expecting. The only explantion I could come up with for this behaivour goes back to Q1; It looks like JS doen't execute it's statements sequentially. Are the any noob tutorials out there that explain HOW JS works, rather than one on structure and syntax ? So far, I haven't found the right set of key words to enter into Google. I didn't officailly start this as a rant, but here goes: [/rant] Thanks in advance. Scot L. Diddle, Richmond VA Quote Link to comment https://forums.phpfreaks.com/topic/122695-why-doesnt-javascript-behave-take-two/ Share on other sites More sharing options...
KevinM1 Posted September 4, 2008 Share Posted September 4, 2008 Show some example code of the problems you're encountering. I'm betting your issues stem from JavaScript's unique sense of scope and/or closures. Quote Link to comment https://forums.phpfreaks.com/topic/122695-why-doesnt-javascript-behave-take-two/#findComment-633594 Share on other sites More sharing options...
ScotDiddle Posted September 4, 2008 Author Share Posted September 4, 2008 Nightsslyr, Thanks for taking the time to respond... My application is interacting with the ZZEE DHTML Menu ( http://www.zzee.com/dhtml-menu/ ) Here is the code where I tried to pass JS parms to PHP... this version concatenates all known values, and sends 'em off once... The original code called: "clk()" for each hit case statement, then alerted that var so-and-so had just sent to PHP. In that scenario, Zend Studio debugger showed one call to transferJSParmToPHP.php, and while it was processing, I got alerts from the rest of the column case statements, and it never called "clk()" again. /** * * See what the user has been up too... * */ function returnChecked() { /* * * Grab the user submitted values and send 'em off to PHP for subsequent processing. * */ // // totalNumberOfColumns set around line 130 in this program. // /** * * Once for each column. * */ for (column = 0; column < totalNumberOfColumns; column++) { // alert (column); // Vis. : 16 checkedIDX = 0; // For each Column, Start with the first child. booleanResponseCount[column] = new Array(); // Create 2nd array level... // Once for each child // Odd column numbers are heading spacers... if (column == 6) { // Tran IDs ( Data Entry ) childCount[column] = 1; // This is a lie... } if (column == 24) { // Reset ( Data Entry ) childCount[column] = 1; // This is a lie... } for (child = 0; child < childCount[column]; child++) { // alert (column); switch (column) { case 0 : checkedBoolean = DBs[child].getChecked(); colText = 'DBs'; break; case 2 : checkedBoolean = SysIDs[child].getChecked(); colText = 'SysIDs'; break; case 4 : checkedBoolean = Metrics[child].getChecked(); colText = 'Metrics'; break; case 6 : checkedBoolean = '$SESSION[\'TranID\']'; colText = 'TranIDs'; break; case 8 : checkedBoolean = DateRangeBoolean[child].getChecked(); colText = 'DateRangeBoolean'; break; case 10 : checkedBoolean = UniqueDateBoolean[child].getChecked(); colText = 'UniqueDateBoolean'; break; case 12 : checkedBoolean = SortOrder[child].getChecked(); colText = 'SortOrder'; break; case 14 : checkedBoolean = DataRestrictions[child].getChecked(); colText = 'DataRestrictions'; break; case 16 : checkedBoolean = DOW[child].getChecked(); colText = 'DOW'; break; case 18 : checkedBoolean = Month[child].getChecked(); colText = 'Month'; // alert(checkedBoolean); break; case 20 : checkedBoolean = Year[child].getChecked(); colText = 'Year'; break; case 22 : checkedBoolean = Documentation[child].getChecked(); colText = 'Documentation'; break; case 24 : checkedBoolean = '$SESSION[\'Reset\']' colText = 'Reset'; break } // Let's see what our childern are up too... // alert ('Col : ' + colText + ' Child: ' + child + ' Boolean : ' + checkedBoolean); booleanResponseCount[column][checkedIDX] = checkedBoolean; checkedIDX++; } // END for (child = 0; child < childCount[column]; child++) { } // END for (column = 0; column < totalNumberOfColumns; column++) { for(i in booleanResponseCount) { if (i == (totalNumberOfColumns -1)) { // alert(booleanResponseCount); // Vis. : 1,0,0,0,,1,0,0,0,0,0,0,0,0,,1,0,0,0,0,0,,$SESSION['TranID'],,1,0,,1,0,,1,0,0,,1,0,0,,1,0,0,0,0,0,0,0,,1,0,0,0,0,0,0,0,0,,1,0,0,,1,0,0,,$SESSION['Reset'], // Col 1 : 1,0,0,0,, // Col 2 : 1,0,0,0,0,0,0,0,0,, // Col 3 : 1,0,0,0,0,0,, // Col 4 : $SESSION['TranID'],, // Col 5 : 1,0,, // Col 6 : 1,0,, // Col 7 : 1,0,0,, // Col 8 : 1,0,0,, // Col 9 : 1,0,0,0,0,0,0,0,, // Col 10 : 1,0,0,0,0,0,0,0,0,, // Col 11 : 1,0,0,, // Col 12 : 1,0,0,, // Col 13 : $SESSION['Reset'], clk('DHTMLResponse', booleanResponseCount) ; } } } // END function returnChecked() { /* * * END post-submit processing * */ /** * * Pass the user's selection to PHP for subsequent decison making... * */ function clk(itemIn,valueIn) { userSelectedItem = itemIn; userSelectedValue = valueIn; switch(userSelectedItem) { case 'DataRestrictionRadioButton' : userSelection = userSelectedItem + '@' + userSelectedValue; break; case 'DHTMLResponse' : userSelection = userSelectedItem + '!' + userSelectedValue; break; default : userSelection = userSelectedItem + '^' + userSelectedValue; break; } // alert(userSelectedValue); passParm = new Image(); iURL="transferJSParamToPHP.php?variable=" + userSelection; passParm.src=iURL; // transferJSParamToPHP.php parses the userSelection and sets // processing instruction via php switch statement... } For my "for (i= ..." issue, here is the relevant code... I used to have each "for" staement like this: "for (i=0; i <= (childCount[colIDX] - 1); i++) {" An alert(i) returned random numbers, but ususally "3"; I found it curious that colIDX was always correct internal to the "for" statements, even though I use the same var name for each loop. /** * * Database Selections column 1 Processing * */ DBs = []; colIDX = 0; /** * * Once for each Database * * */ for (a=0; a <= (childCount[colIDX] - 1); a++) { DBs[a] = menu[menuIDX].getItem([colIDX, a]); DBs[a].setRadio(0); DBs[a].onclick = function() { // this.setChecked(!this.getChecked()); this.setChecked(true); }; // We need to set the initial state of the checkbox item DBs[a].setChecked(false); }; // Default for DB Selection: DBs[0].setChecked(true); /** * * SysIDs column 2 Processing * */ SysIDs = []; colIDX = 2; /** * * SysIDs[<?php echo $SysIDLast; ?>] = 'ALL' * * (currently : 9) * * :: When clicked, we need to turn off all SysIDs's * already selected. * */ // Set up SysIDs[9] first, because it will be referenced immediately... // Set up the last SysID <?php $SysIDLast = $_SESSION['SysIDCount'] - 1; $countOfPreviousSysIDs = $_SESSION['SysIDCount'] - 2; ?> allOff = ''; SysIDChildCount = <?php echo $countOfPreviousSysIDs ; ?> SysIDs[<?php echo $SysIDLast; ?>] = menu[menuIDX].getItem([colIDX, <?php echo $SysIDLast; ?>]); SysIDs[<?php echo $SysIDLast; ?>].setRadio(1); SysIDs[<?php echo $SysIDLast; ?>].onclick = function() { this.setChecked(!this.getChecked()); if (this.getChecked()) { // Here we see if any other SysIDs's have previously been selected, // and turn them off if they have been. for (b = 0; b <= <?php echo $countOfPreviousSysIDs; ?>; b++) { // Re-set the initial state of the checkbox item SysIDs[b].setChecked(true); } // END: for (b=0; b<=$countOfPreviousSysIDs; b++) { } // END: if (this.getChecked()) { else { // User turned off the "ALL" button... Resest other buttons to default for (b=0; b<=<?php echo $countOfPreviousSysIDs; ?>; b++) { // Re-set the initial state of the checkbox item SysIDs[b].setChecked(false); } // END: for (b=0; b<= $countOfPreviousSysIDs; b++) { SysIDs[0].setChecked(true); } returnChecked(); // See what the user did and save if for post-submit processing. }; // END: SysIDs[9].onclick = function() { /** * * Once for each SysIDs * * */ for (c = 0; c<=<?php echo $countOfPreviousSysIDs; ?>; c++) { SysIDs[c] = menu[menuIDX].getItem([colIDX, c]); SysIDs[c].onclick = function() { this.setChecked(!this.getChecked()); if ( SysIDs[<?php echo $countOfPreviousSysIDs; ?> + 1].getChecked()) { SysIDs[c - 1].setChecked(false); } searchResult = checkSysIDs(SysIDChildCount); // Don't let the user leave things blank... if (searchResult == 'All Off') { SysIDs[0].setChecked(true); } allOff = ''; returnChecked(); // See what the user did and save it for post-submit processing. }; // We need to set the initial state of the checkbox item SysIDs[c].setChecked(false); } // Select at least one SysIDs... SysIDs[0].setChecked(true); /** * * Metric Selections column 3 Processing * */ Metrics = []; colIDX = 4; /** * * Once for each Metric * * */ for (d = 0; d <= (childCount[colIDX] - 1); d++) { Metrics[d] = menu[menuIDX].getItem([colIDX, d]); Metrics[d].setRadio(2); Metrics[d].onclick = function() { this.setChecked(!this.getChecked()); // Don't let the user leave things blank... if ( (Metrics[0].getChecked() == false ) && (Metrics[1].getChecked() == false ) && (Metrics[2].getChecked() == false ) && (Metrics[3].getChecked() == false ) && (Metrics[4].getChecked() == false ) && (Metrics[5].getChecked() == false ) ) { Metrics[0].setChecked(true); } returnChecked(); // See what the user did and save it for post-submit processing. }; // We need to set the initial state of the checkbox item Metrics[d].setChecked(false); }; // Default for Metrics Selection: Metrics[0].setChecked(true); /** * * Trans ID column 4 Processing * */ /** * * // Trans ID overLib Caption fits here. * * Trans ID Processing takes place in : 'javascript/UpgfDHTMLMenuGenerator.js' * * in function: ZZME.prototype.mover=function(ev) { * * as a call to : overLibDisplay(currentColumn); * * where currentColumn is defined as: this.caption * * colIDX = 6; * */ /** * * Date Range column 5 Processing * */ /** * * Once for each Metric Date Range Radio button (Two: Yes or No) * * */ DateRangeBoolean = []; colIDX = 8; for (e = 0; e <= (childCount[colIDX] - 1); e++) { DateRangeBoolean[e] = menu[menuIDX].getItem([colIDX, e]); DateRangeBoolean[e].setRadio(3); DateRangeBoolean[e].onclick = function() { this.setChecked(!this.getChecked()); // Don't let the user leave things blank... if ( (DateRangeBoolean[0].getChecked() == false ) && (DateRangeBoolean[1].getChecked() == false ) ) { DateRangeBoolean[0].setChecked(true); } returnChecked(); // See what the user did and save it for post-submit processing. }; // We need to set the initial state of the checkbox item DateRangeBoolean[e].setChecked(false); }; // Default for DateRangeBoolean Selection: DateRangeBoolean[0].setChecked(true) /** * * Unique Date column 6 Processing * */ /** * * Once for each Date Uniqueness Query Range Radio buttons (Two: true or false) * * */ UniqueDateBoolean = []; colIDX = 10; for (f = 0; f <= (childCount[colIDX] - 1); f++) { UniqueDateBoolean[f] = menu[menuIDX].getItem([colIDX, f]); UniqueDateBoolean[f].setRadio(4); UniqueDateBoolean[f].onclick = function() { this.setChecked(!this.getChecked()); // Don't let the user leave things blank... if ( (UniqueDateBoolean[0].getChecked() == false ) && (UniqueDateBoolean[1].getChecked() == false ) ) { UniqueDateBoolean[0].setChecked(true); } returnChecked(); // See what the user did and save it for post-submit processing. }; // We need to set the initial state of the checkbox item UniqueDateBoolean[f].setChecked(false); }; // Default for UniqueDateBoolean Selection: UniqueDateBoolean[0].setChecked(true); /** * * Sort column 7 Processing * */ /** * * Once for each SortOrder Option Radio Button ( Three to choose from ) * * */ SortOrder = []; colIDX = 12; for (g = 0; g <= (childCount[colIDX] - 1); g++) { SortOrder[g] = menu[menuIDX].getItem([colIDX, g]); SortOrder[g].setRadio(5); SortOrder[g].onclick = function() { this.setChecked(!this.getChecked()); // Don't let the user leave things blank... if ( (SortOrder[0].getChecked() == false ) && (SortOrder[1].getChecked() == false ) && (SortOrder[2].getChecked() == false ) ) { SortOrder[0].setChecked(true); } returnChecked(); // See what the user did and save it for post-submit processing. }; // We need to set the initial state of the checkbox item SortOrder[g].setChecked(false); }; // Default for SortOrder Selection: SortOrder[0].setChecked(true); /** * * Data Restrictions column 8 Processing * */ /** * * Once for each Data Restriction Option Radio Button ( Three to choose from ) * */ DataRestrictions = []; colIDX = 14; for (h = 0; h <= (childCount[colIDX] - 1);h++) { DataRestrictions[h] = menu[menuIDX].getItem([colIDX, h]); DataRestrictions[h].setRadio(6); DataRestrictions[h].onclick = function() { this.setChecked(!this.getChecked()); /* * * Send off the user's selection to PHP so we can decide later, * * (in AJAXAutoSuggest.php) which array of values we present to the user. * * case 'TopX' : * $dataArrayIn = $topX; * break; * * case 'LowX' : * $dataArrayIn = $lowX; * break * */ if (DataRestrictions[1].getChecked() == true) { clk('DataRestrictionRadioButton', 1); } if (DataRestrictions[2].getChecked() == true) { clk('DataRestrictionRadioButton', 2); } // Debug toggle: debug = false; if(debug) { // alert('Debug Mode'); } // Turn on overLib if user is requesting limits... if ( (DataRestrictions[1].getChecked() == true) || (DataRestrictions[2].getChecked() == true) ) { if (DataRestrictions[1].getChecked() == true) { if (debug) { // Eliminate MOUSEOFF parm... return overlib('', SRC, 'autoSuggestRestrictions.php', TIMEOUT, 4500, CAPTION, '<font color=#F6F9F9> High Range Limit </font><br/><br/>', CAPTIONSIZE, '9px', WIDTH, 440, HEIGHT, 420, STICKY, CENTER, WRAP, FIXX, 496, FIXY, 38, FGCOLOR, '#F6F9F9', BGCOLOR, 'GREEN', CLOSECOLOR, '#F6F9F9', NOBORDER, VAUTO, FOLLOWSCROLL, CLOSECOLOR, '#F6F9F9', CLOSETEXT, '<font="verdana" size="12px"><stong>X</font></strong><br /><br/>' ); } else { return overlib('', SRC, 'autoSuggestRestrictions.php', TIMEOUT, 4500, CAPTION, '<font color=#F6F9F9> High Range Limit </font><br/><br/>', CAPTIONSIZE, '9px', WIDTH, 440, HEIGHT, 420, STICKY, CENTER, WRAP, FIXX, 496, FIXY, 38, FGCOLOR, '#F6F9F9', BGCOLOR, 'GREEN', CLOSECOLOR, '#F6F9F9', NOBORDER, VAUTO, MOUSEOFF, FOLLOWSCROLL, CLOSECOLOR, '#F6F9F9', CLOSETEXT, '<font="verdana" size="12px"><stong>X</font></strong><br /><br/>' ); } } if (DataRestrictions[2].getChecked() == true) { if (debug) { // Eliminate MOUSEOFF parm... return overlib('', SRC, 'autoSuggestRestrictions.php', TIMEOUT, 4500, CAPTION, '<font color=#F6F9F9> Low Range Limit </font><br/><br/>', CAPTIONSIZE, '9px', WIDTH, 440, HEIGHT, 420, STICKY, CENTER, WRAP, FIXX, 496, FIXY, 38, FGCOLOR, '#F6F9F9', BGCOLOR, 'GREEN', CLOSECOLOR, '#F6F9F9', NOBORDER, VAUTO, FOLLOWSCROLL, CLOSECOLOR, '#F6F9F9', CLOSETEXT, '<font="verdana" size="12px"><stong>X</font></strong><br /><br/>' ); } else { return overlib('', SRC, 'autoSuggestRestrictions.php', TIMEOUT, 4500, CAPTION, '<font color=#F6F9F9> Low Range Limit </font><br/><br/>', CAPTIONSIZE, '9px', WIDTH, 440, HEIGHT, 420, STICKY, CENTER, WRAP, FIXX, 496, FIXY, 38, FGCOLOR, '#F6F9F9', BGCOLOR, 'GREEN', CLOSECOLOR, '#F6F9F9', NOBORDER, VAUTO, MOUSEOFF, FOLLOWSCROLL, CLOSECOLOR, '#F6F9F9', CLOSETEXT, '<font="verdana" size="12px"><stong>X</font></strong><br /><br/>' ); } } } // Don't let the user leave things blank... if ( (DataRestrictions[0].getChecked() == false ) && (DataRestrictions[1].getChecked() == false ) && (DataRestrictions[2].getChecked() == false ) ) { DataRestrictions[0].setChecked(true); } returnChecked(); // See what the user did and save it for post-submit processing. }; // We need to set the initial state of the checkbox item DataRestrictions[h].setChecked(false); }; // Default for DataRestrictions Selection: DataRestrictions[0].setChecked(true) /** * * DOW column 9 Processing * */ /** * * Once for each DOW Option Radio Button ( Eight to choose from ) * * */ DOW = []; colIDX = 16; for (i = 0; i <= (childCount[colIDX] - 1); i++) { DOW[i] = menu[menuIDX].getItem([colIDX, i]); DOW[i].setRadio(7); DOW[i].onclick = function() { this.setChecked(!this.getChecked()); // Don't let the user leave things blank... if ( (DOW[0].getChecked() == false ) && (DOW[1].getChecked() == false ) && (DOW[2].getChecked() == false ) && (DOW[3].getChecked() == false ) && (DOW[4].getChecked() == false ) && (DOW[5].getChecked() == false ) && (DOW[6].getChecked() == false ) && (DOW[7].getChecked() == false ) ) { DOW[0].setChecked(true); } returnChecked(); // See what the user did and save it for post-submit processing. }; // We need to set the initial state of the checkbox item DOW[i].setChecked(false); }; // Default for SortOrder Selection: DOW[0].setChecked(true); /** * * Month column 10 Processing * */ /** * * Once for each Month Option Radio Button ( 13 to choose from ) * * */ Month = []; colIDX = 18; allOff = ''; monthChildCount = childCount[colIDX]; for (j = 0; j <= (childCount[colIDX] - 1); j++) { Month[j] = menu[menuIDX].getItem([colIDX, j]); Month[j].setRadio(; Month[j].onclick = function() { checkedResult = this.setChecked(!this.getChecked()); // Don't let the user leave things blank... searchResult = checkMonths(monthChildCount); if (searchResult == 'All Off') { Month[0].setChecked(true); } allOff = ''; returnChecked(); // See what the user did and save it for post-submit processing. }; // We need to set the initial state of the checkbox item Month[j].setChecked(false); }; // Default for Month Selection: Month[0].setChecked(true); /** * * Year column 11 Processing * */ /** * * Once for each Year Option Radio Button ( Number to choose from Varies ) * * */ Year = []; colIDX = 20; currentChildCount = childCount[colIDX]; allOff = ''; for (k = 0; k <= (childCount[colIDX] - 1); k++) { Year[k] = menu[menuIDX].getItem([colIDX, k]); Year[k].setRadio(9); Year[k].onclick = function() { this.setChecked(!this.getChecked()); // Don't let the user leave things blank... searchResult = checkYears(currentChildCount); if (searchResult == 'All Off') { Year[0].setChecked(true); } allOff = ''; returnChecked(); // See what the user did and save it for post-submit processing. }; // We need to set the initial state of the checkbox item Year[k].setChecked(false); }; // Default for SortOrder Selection: Year[0].setChecked(true); /** * * Documentation column 12 Processing * */ /** * * Once for each Documentation Option Radio Button ( 3 to choose from ) * * */ Documentation = []; colIDX = 22; for (l = 0; l <= (childCount[colIDX] - 1); l++) { Documentation[l] = menu[menuIDX].getItem([colIDX, l]); Documentation[l].setRadio(10); Documentation[l].onclick = function() { this.setChecked(!this.getChecked()); // Don't let the user leave things blank... if ( (Documentation[0].getChecked() == false ) && (Documentation[1].getChecked() == false ) && (Documentation[2].getChecked() == false ) ) { Documentation[0].setChecked(true); } returnChecked(); // See what the user did and save it for post-submit processing. }; // We need to set the initial state of the checkbox item Documentation[l].setChecked(false); }; // Default for SortOrder Selection: Documentation[0].setChecked(true); /** * * Reset column 13 Processing * */ /** * * No Children * * */ Reset = []; colIDX = 24; /** * * END DHTML Menu Generation * */ Just for giggles, here is the code which instantiates the ZZEE DHTML Menu : It lies just before the previous code /** * * 'include/metricsMenu.js' * * Called from 'DHTMLViaArrayProcessing.php' around line 354 as a PHP require include. * * Used to set up the initial DHTML JS Menu for the user interface. * */ /** * * Add Items to the new menu... * */ menu[menuIDX].addItems([ // Menu Col IDX : 0 -> Menu Item 1 {caption: "DB", subitems: [ // Here go the subitems of First. You can define subitems for any menu item. // Subitems syntax is absolutely the same as the syntax for "addItems" call: // you need to pass an array of objects. {caption: "CICS"}, {caption: "MVS", en: false}, {caption: "DB2", en: false}, {caption: "LINUX", en: false} ]}, // Separator Menu Col IDX : 1 {caption: "-"}, // Menu Col IDX : 2 -> Menu Item 2 {caption: "SysIDs", subitems: [ // // {caption: "AOR1"}, // Check box.. // {caption: "AOR2"}, // Check box.. // {caption: "AOR3"}, // Check box.. // {caption: "AOR4"}, // Check box.. // {caption: "AOR5"}, // Check box.. // {caption: "AOR6"}, // Check box.. // {caption: "AOR7"}, // Check box.. // {caption: "FAF1"}, // Check box.. // {caption: "ODM1"}, // Check box.. // {caption: "ALL"} // Radio button... If on, all SysID check boxes are turned off. // // If turn off after having been turned on, // // Item 0 will be turned on.... <?php foreach($_SESSION['SysIDJS'] as $IDX => $SysIDCaption) { if ($IDX === 0) { $SysIDCaptionOut = "\t" . $SysIDCaption . "\n"; } else { $SysIDCaptionOut = "\t\t" . $SysIDCaption . "\n"; } echo $SysIDCaptionOut; } ?> ]}, // Separator Menu Col IDX : 3 {caption: "-"}, // Menu Col IDX : 4 -> Menu Item 3 {caption: "Metrics", subitems: [ // Here go the subitems of First. You can define subitems for any menu item. // Subitems syntax is absolutely the same as the syntax for "addItems" call: // you need to pass an array of objects. {caption: "1 : Hourly Tran Count by SysID"}, {caption: "2 : Tran Response Time By SysID"}, {caption: "3 : Hourly Tran CPU Utilization By SysID (Under Construction)", en: false}, {caption: "4 : Tran Count By TranID"}, {caption: "5 : Tran Response Time By TranID"}, {caption: "6 : Tran CPU Utilization By TranID (Under Construction)", en: false} ]}, // Separator Menu Col IDX : 5 {caption: "-"}, /** * * Tran IDs : Menu Col IDX : 6 -> Menu Item 4 * * No Childern: Input Box * * overLib Loaded: autoSuggest.php * */ {caption: "Tran IDs"}, // Separator Menu Col IDX : 7 {caption: "-"}, /** * * Date Range Boolean Query : Menu Col IDX : 8 -> Menu Item 5 * */ {caption: "Date Range", subitems: [ {caption: "No"}, {caption: "Yes"} ]}, // Separator Menu Col IDX : 9 {caption: "-"}, /** * * Unique Date Boolean Query : Menu Col IDX : 10 -> Menu Item 6 * */ {caption: "Unique Dates", subitems: [ {caption: "No"}, {caption: "Yes"} ]}, // Separator Menu Col IDX : 11 {caption: "-"}, /** * * Sort Query : Menu Col IDX : 12 -> Menu Item 7 * */ {caption: "Sort", subitems: [ {caption: "Tran ID"}, {caption: "Low To High"}, {caption: "High To Low"} ]}, // Separator Menu Col IDX : 13 {caption: "-"}, /** * * Data Restrictions : Menu Col IDX : 14 -> Menu Item 8 * * Three Childern, two of which call an input box * * overLib Loaded: autoSuggestRestriction.php * */ {caption: "Data Restrictions", subitems: [ {caption: "No Restrictions"}, {caption: "Top \"x\""}, {caption: "Low \"x\""} ]}, // Separator Menu Col IDX : 15 {caption: "-"}, /** * * Day of Week Query : Menu Col IDX : 16 -> Menu Item 9 * */ {caption: "DOW", subitems: [ {caption: "N/A"}, {caption: "Mon"}, {caption: "Tue"}, {caption: "Wed"}, {caption: "Thu"}, {caption: "Fri"}, {caption: "Sat"}, {caption: "Sun"} ]}, // Separator Menu Col IDX : 17 {caption: "-"}, /** * * DB Calls generates the following two PHP values ($monthJS and $yearJS) * * ( Line: 97 in : 'DHTMLViaArrayProcessing.php' ) * */ /** * * Month Query : Menu Col IDX : 18 -> Menu Item 10 * */ {caption: "Month", subitems: [ <?php foreach($_SESSION['monthJS'] as $IDX => $monthCaption) { if ($IDX === 0) { $monthCaptionOut = "\t" . $monthCaption . "\n"; } else { $monthCaptionOut = "\t\t" .$monthCaption . "\n"; } echo $monthCaptionOut; } ?> ]}, // Separator Menu Col IDX : 19 {caption: "-"}, /** * * Year Query : Menu Col IDX : 20 -> Menu Item 11 * */ {caption: "Year", subitems: [ <?php foreach($_SESSION['yearJS'] as $IDX => $yearCaption) { if ($IDX === 0) { $yearCaptionOut = "\t" . $yearCaption . "\n"; } else { $yearCaptionOut = "\t\t" . $yearCaption . "\n"; } echo $yearCaptionOut; } ?> ]}, // Separator Menu Col IDX : 21 {caption: "-"}, /** * * Documentation Query : Menu Col IDX : 22 -> Menu Item 12 * */ {caption: "Documentation", subitems: [ {caption: "User Interface"}, {caption: "Programming"}, {caption: "Graph OOP"} ]}, // Separator Menu Col IDX : 23 {caption: "-"}, /** * * Rest : Menu Col IDX : 24 -> Menu Item 13 * */ {caption: "Reset"}, // Separator Menu Col IDX : 25 {caption: "-"} ]); Quote Link to comment https://forums.phpfreaks.com/topic/122695-why-doesnt-javascript-behave-take-two/#findComment-633621 Share on other sites More sharing options...
KevinM1 Posted September 4, 2008 Share Posted September 4, 2008 For the first problem, mind showing the PHP that's supposed to handle the newly formed images? And for the second, are all for-loops screwing up, or just the first? Quote Link to comment https://forums.phpfreaks.com/topic/122695-why-doesnt-javascript-behave-take-two/#findComment-633874 Share on other sites More sharing options...
ScotDiddle Posted September 5, 2008 Author Share Posted September 5, 2008 NightSlyr, When all of the "for" loops had "i" as the var name, some would work, and some would not... It was never consistant, even if I made the same DHTML menu selections one test after another. Ones that "worked" on one pass may, or may not alert the same value for "i" on subsequent tests using the exact same user selections. Once I went to unique var names, I got the expected results every time. Here is my new Image() code: Thanks. Scot L. Diddle, Richmond VA <?php $getVariable = $_GET['variable']; $DHTMLResponseParm = $getVariable; $DHTMLResponseParmQuery = stristr($getVariable,'DHTMLResponse!'); if ($DHTMLResponseParmQuery) { // Make the passed DHTML Parm into something human-readable... $DHTMLPassedParmsPieces = explode('!', $DHTMLResponseParm); $DHTMLHeading = $DHTMLPassedParmsPieces[0]; $DHTMLData = $DHTMLPassedParmsPieces[1]; $DHTMLDataPieces = explode(',,', $DHTMLData); $newDHTMLArray = array(); foreach ($DHTMLDataPieces as $IDX => $DHTMLDataOut) { switch($IDX) { case 0; $newDHTMLArray[$IDX] = 'DBs%' . $DHTMLDataOut; break; case 1; $newDHTMLArray[$IDX] = '|SysIDs%' . $DHTMLDataOut; break; case 2; $newDHTMLArray[$IDX] = '|Metrics%' . $DHTMLDataOut; break; case 3; $newDHTMLArray[$IDX] = '|TransID%' . $DHTMLDataOut; break; case 4; $newDHTMLArray[$IDX] = '|DateRange%' . $DHTMLDataOut; break; case 5; $newDHTMLArray[$IDX] = '|UniqueDates%' . $DHTMLDataOut; break; case 6; $newDHTMLArray[$IDX] = '|Sort%' . $DHTMLDataOut; break; case 7; $newDHTMLArray[$IDX] = '|DataRestrictions%' . $DHTMLDataOut; break; case 8; $newDHTMLArray[$IDX] = '|DOW%' . $DHTMLDataOut; break; case 9; $newDHTMLArray[$IDX] = '|Month%' . $DHTMLDataOut; break; case 10; $newDHTMLArray[$IDX] = '|Year%' . $DHTMLDataOut; break; case 11; $newDHTMLArray[$IDX] = '|Documentation%' . $DHTMLDataOut; break; case 12; $newDHTMLArray[$IDX] = '|Reset%' . $DHTMLDataOut; break; } // END switch($IDX) { } //END foreach ($DHTMLDataPieces as $IDX => $DHTMLDataOut) { $getVariable = $DHTMLHeading . '!' . implode('', $newDHTMLArray); } // END if ($DHTMLResponseParmQuery) { $_SESSION['variable'] = $getVariable; if (stristr($getVariable,'@')) { $_SESSION['autoSuggestRestrictionVar'] = $_SESSION['variable']; } $userInputQuery = stristr($getVariable, 'DHTMLResponse!'); if ($userInputQuery) { $_SESSION['POST'] = $_SESSION['variable']; } require('placeParm.php'); // Go find out what to do with the incoming JS parm value... ?> and: pllaceParm.php: <?php $callingProgram = $_SESSION['callingProgram']; $passedJavascriptParm = $_SESSION['variable']; $autoSuggestParm = FALSE; $DHTMLProcessing = FALSE; switch ($callingProgram) { case 'autoSuggest.php' : $savePHPElements = $passedJavascriptParm; $PaamayimNekudotayimSearch = stristr($passedJavascriptParm,'::'); // Set around line 193 in 'include/AJAXAutoSuggest.php' if ($PaamayimNekudotayimSearch) { $passedJavascriptParm = explode('::', $passedJavascriptParm); } $passedJavascriptParm = $passedJavascriptParm[0]; $passedJavascriptParm = trim($passedJavascriptParm ); $tranIDOut = array(); $autoSuggestParm = TRUE; $currentArray = $_SESSION['autoSuggestTranIDs']; $deleteResults = deleteFromArray($currentArray, $passedJavascriptParm, FALSE); if (is_array($deleteResults)) { $returnedArray = $deleteResults; $_SESSION['autoSuggestTranIDs'] = $returnedArray; } $DHTMLResponseQuery = stristr($savePHPElements, 'DHTMLResponse!'); $radioButtonQuery = stristr($savePHPElements, 'DataRestrictionRadioButton'); $commaQuery = stristr($savePHPElements, ','); if ( (!$DHTMLResponseQuery) && (!$radioButtonQuery) && (!$commaQuery) ) { $_SESSION['usersSelectedTranID'][] = $savePHPElements; } break; case 'DHTMLViaArrayProcessing.php' : $DHTMLProcessing = TRUE; $savePHPElements = $passedJavascriptParm; $atSearch = stristr($passedJavascriptParm,'@'); // // Set in 'DHTMLViaArrayProcessing.php' around line 904 in function clk() { // // via : (javascript) // // case 'DataRestrictionRadioButton' : // userSelection = userSelectedItem + '@' + userSelectedValue; // break; // // Used to determine which direction the user restrictions travel... // if ($atSearch) { $passedJavascriptParm = explode('@', $passedJavascriptParm); $passedJavascriptParm = $passedJavascriptParm[1]; $passedJavascriptParm = trim($passedJavascriptParm ); $autoSuggestParm = TRUE; if($passedJavascriptParm == 1) { $currentArray = $_SESSION['autoSuggestRestrictionLimitTop']; } if($passedJavascriptParm == 2) { $currentArray = $_SESSION['autoSuggestRestrictionLimitLow']; } } $bangSearch = stristr($passedJavascriptParm,'!'); if ($bangSearch) { unset($_SESSION['DHTMLPassedParm']); $_SESSION['DHTMLPassedParm'] = $passedJavascriptParm; // Vis. : DHTMLResponse!1,0,0,0,,1,0,0,0,0,0,0,0,0,0,,1,0,0,0,0,0,,$_SESSION['TranIDs],,1,0,,1,0,,1,0,0,,$_SESSION['DataRestrictions], } break; case 'autoSuggestRestrictions.php' : $savePHPElements = $passedJavascriptParm; $asterixSearch = stristr($passedJavascriptParm,'*'); // // Set around line 180 in 'autoSuggestRestrictions.php' // // Vis.: passedVariable = 'restrictionLimit' + '*' + userSelectedRestrictionLimit[idx]; // // Used to save the user selected restriction for display on subsequent calls // to overLib display via "Show". // if ($asterixSearch) { $passedJavascriptParm = explode('*', $passedJavascriptParm); $passedJavascriptParm = $passedJavascriptParm[1]; $passedJavascriptParm = trim($passedJavascriptParm ); $_SESSION['autoSuggestRestrictionLimit'] = array(); $_SESSION['autoSuggestRestrictionLimit'][0] = $passedJavascriptParm; } break; } if ( (!$autoSuggestParm) && (!$DHTMLProcessing) ) { // Turn on to produce Error... // $passedJavascriptParm = 'Hi Mom'; $functionLine = __LINE__ + 2; $stristrResult1 = stristr($passedJavascriptParm,'SORT'); if ($stristrResult1) { // Then incoming param is a complex type, which must be broken down // into constituient components... $pieces = explode('@', $passedJavascriptParm); $passedJavascriptType = $pieces[0]; $passedJavascriptParm = $passedJavascriptType; } $switchResult = checkParm($passedJavascriptParm); if (!$switchResult) { $stristrResult2 = stristr($passedJavascriptParm, '~'); if ($stristrResult2) { // Then incoming param is a complex type, which must be broken down // into constituient components... $widthAndHeight = explode('~', $passedJavascriptParm ); foreach($widthAndHeight as $oneOrTheOther) { $pieces = explode('@', $oneOrTheOther); $lenghtOrWidth = $pieces[1]; $passedJavascriptParmArray[$pieces[1]][] = $pieces[0]; } $passedJavascriptParm = $passedJavascriptParmArray; } else { $stristrResult3 = stristr($passedJavascriptParm,'tableName'); if ($stristrResult3) { $pieces = explode('@', $passedJavascriptParm); $passedJavascriptParm = $pieces[0]; $_SESSION['selectedTable'] = $pieces[2]; $checkJavascriptParm = $passedJavascriptParm; switchOnPassedParmType($checkJavascriptParm,$whichParam = NULL); } } // If an array is the result of breaking down an incoming complex param, process each array item... if (is_array($passedJavascriptParm)) { foreach($passedJavascriptParm as $IDX => $javascriptParm) { if (($IDX == 'W') || ($IDX == 'H')) { $whichParam = $IDX; $checkJavascriptParm = $passedJavascriptParm[$IDX][0]; } if ($whichParam == 'W') { $_SESSION['javascriptScreenWidth'] = $passedJavascriptParm[$IDX][0]; } if ($whichParam == 'H') { $_SESSION['javascriptScreenHeight'] = $passedJavascriptParm[$IDX][0]; } } } } function switchOnPassedParmType($checkJavascriptParm,$whatTypeOfParamDoesSwitchHaveToDealWith) { $_SESSION['paramValue'] = $checkJavascriptParm; $_SESSION['paramType'] = $whatTypeOfParamDoesSwitchHaveToDealWith; $isInt = checkInt($checkJavascriptParm); if ($isInt) { $passedJavascriptParm = 'INT'; } else { $passedJavascriptParm = $checkJavascriptParm; } $functionLine = __LINE__ + 2; $switchResult = checkParm($passedJavascriptParm); if(!$switchResult) { $_SESSION['placeParmSwitchError'] = "UNKNOWN Javascript Parm (\$passedJavascriptParm :: $passedJavascriptParm) passed to PlaceParm.php...<br /><br />See Line : $functionLine in program 'placeParm.php'. The Parm came from the javascript function clk(param); in <br /><br /><ul><ul>'UpgfDateSelect.php' around Line 1960, and is fed in either<br /><br /><ul><ul>'UpgfDateSelect.php' or 'buildUIQuery.php' </ul></ul></ul></ul> \n"; } else { unset($_SESSION['placeParmSwitchError']); } } function checkInt($i) { // return 0 if not int and return 1 if $i is int if (ereg("^[0-9]+[.]?[0-9]*$", $i, $p)) { return 1; } else { return 0; } } } function checkParm($parameterToCheck) { $passedJavascriptParm = $parameterToCheck; switch($passedJavascriptParm) { case 'resetSession' : /** * * Set in 'include/UpgfMetricsCloseLevel1Window.php' * */ require('include/resetSession.php'); break; case 'INT' : if ($_SESSION['paramType'] == 'W') { $_SESSION['javascriptScreenWidth'] = $_SESSION['paramValue']; } if ($_SESSION['paramType'] == 'H') { $_SESSION['javascriptScreenHeight'] = $_SESSION['paramValue']; } break; case 'dateSelect' : case 'dateRange' : $_SESSION['javascriptDateParm'] = $passedJavascriptParm; break; case 'Internet Explorer' : case 'Firefox' : $_SESSION['usersBrowser'] = $passedJavascriptParm; break; case 'PDFYes' : $_SESSION['generatePDF'] = TRUE; break; case 'PDFNo' : $_SESSION['generatePDF'] = FALSE; break; case 'dateRangeTrue' : $_SESSION['dateRangeQuery'] = TRUE; break; case 'dateRangeFalse' : $_SESSION['dateRangeQuery'] = FALSE; break; case 'newTableSelected' : $selectedTable = $_SESSION['selectedTable']; $functionLine = __LINE__ + 2; switch($selectedTable) { case 'Tran_Count_By_Date' : $_SESSION['returnTrip'] = TRUE; $_SESSION['choosenSysIDTable'] = 'Tran_Count_Per_Hour_By_SysID'; $_SESSION['chooseSysIDTableChanged'] = TRUE; $_SESSION['indelibleTable'] = 'tran_count_by_date'; $_SESSION['indelibleDocFormat'] = 'tran_count_by_date'; $_SESSION['displayTableName'] = 'Tran_Count_Per_Hour_By_SysID'; $_SESSION['tableAlias'] = 'Tran_Count_Per_Hour_By_SysID'; $_SESSION['respTimeQueryBoolean'] = FALSE; break; case 'Tran_Response_Time_By_Date' : $_SESSION['returnTrip'] = TRUE; $_SESSION['choosenSysIDTable'] = 'Tran_Response_Time_By_Date'; $_SESSION['chooseSysIDTableChanged'] = TRUE; $_SESSION['indelibleTable'] = 'tran_count_by_date'; $_SESSION['indelibleDocFormat'] = 'tran_count_by_date'; $_SESSION['displayTableName'] = 'Tran_Response_Time_By_Date'; $_SESSION['tableAlias'] = 'Tran_Response_Time_By_Date'; $_SESSION['respTimeQueryBoolean'] = TRUE; break; case 'Transactions_By_Count' : $_SESSION['returnTrip'] = TRUE; $_SESSION['choosenSysIDTable'] = 'Tran_Count_Per_Day_By_TransID'; $_SESSION['chooseSysIDTableChanged'] = TRUE; $_SESSION['indelibleTable'] = 'transactions_by_count'; $_SESSION['indelibleDocFormat'] = 'transactions_by_count'; $_SESSION['displayTableName'] = 'Tran_Count_Per_Day_By_TransID'; $_SESSION['tableAlias'] = 'Tran_Count_Per_Day_By_TransID'; $_SESSION['respTimeQueryBoolean'] = FALSE; break; case 'Tran_Response_Time_By_TranID' : $_SESSION['returnTrip'] = TRUE; $_SESSION['choosenSysIDTable'] = 'Tran_Response_Time_By_TranID'; $_SESSION['chooseSysIDTableChanged'] = TRUE; $_SESSION['indelibleTable'] = 'transactions_by_count'; $_SESSION['indelibleDocFormat'] = 'transactions_by_count'; $_SESSION['displayTableName'] = 'tran_response_time_by_tranid'; $_SESSION['tableAlias'] = 'tran_response_time_by_tranid'; $_SESSION['respTimeQueryBoolean'] = TRUE; break; default : $varName = $selectedTable; if (!isset($varName)) { $varName = '*** Not Set ***'; } if (!$varName == NULL) { $varName = '*** Null ***'; } $_SESSION['errorTable'] = $selectedTable; $_SESSION['errorProgram'] = 'placeParm.php'; $_SESSION['chooseTableErrorBoolean'] = TRUE; $_SESSION['functionLine'] = $functionLine; break; } break; // The following case is true if the user hit the reset button // during 'UpgfMetricsDateSelectChoose.php processing... case 'chooseDateResetRequest' : $selectedTable = 'Transactions_By_Count'; $_SESSION['returnTrip'] = TRUE; $_SESSION['choosenSysIDTable'] = 'Transactions_By_Count'; $_SESSION['chooseSysIDTableChanged'] = TRUE; $_SESSION['indelibleTable'] = 'Transactions_By_count'; $_SESSION['indelibleDocFormat'] = 'Transactions_By_count'; $_SESSION['respTimeQueryBoolean'] = FALSE; $_SESSION['displayTableName'] = 'Transactions_By_count'; break; // The following case is true if the user hit the reset button // during 'UpgfMetricsDateSelect.php processing... case 'dateResetRequest' : $numberOfSysIDsChoosen = $_SESSION['countOfChoosenSysIDs']; if ($numberOfSysIDsChoosen > 1) { $_SESSION['patientsRequired'] = TRUE; } else { $_SESSION['patientsRequired'] = FALSE; } break; case 'AOR1' : if (!isset($_SESSION['AOR1Selected'])) { $_SESSION['AOR1Selected'] = TRUE; } else { $_SESSION['AOR1Selected'] = FALSE; } break; case 'AOR2' : if (!isset($_SESSION['AOR2Selected'])) { $_SESSION['AOR2Selected'] = TRUE; } else { $_SESSION['AOR2Selected'] = FALSE; } break; case 'AOR3' : if (!isset($_SESSION['AOR3Selected'])) { $_SESSION['AOR3Selected'] = TRUE; } else { $_SESSION['AOR3Selected'] = FALSE; } break; case 'AOR4' : if (!isset($_SESSION['AOR4Selected'])) { $_SESSION['AOR4Selected'] = TRUE; } else { $_SESSION['AOR4Selected'] = FALSE; } break; case 'AOR5' : if (!isset($_SESSION['AOR5Selected'])) { $_SESSION['AOR5Selected'] = TRUE; } else { $_SESSION['AOR5Selected'] = FALSE; } break; case 'AOR6' : if (!isset($_SESSION['AOR6Selected'])) { $_SESSION['AOR6Selected'] = TRUE; } else { $_SESSION['AOR6Selected'] = FALSE; } break; case 'AOR7' : if (!isset($_SESSION['AOR7Selected'])) { $_SESSION['AOR7Selected'] = TRUE; } else { $_SESSION['AOR7Selected'] = FALSE; } break; case 'FAF1' : if (!isset($_SESSION['FAF1Selected'])) { $_SESSION['FAF1Selected'] = TRUE; } else { $_SESSION['FAF1Selected'] = FALSE; } break; case 'ODM1' : if (!isset($_SESSION['ODM1Selected'])) { $_SESSION['ODM1Selected'] = TRUE; } else { $_SESSION['ODM1Selected'] = FALSE; } break; case 'AOR1' : if (!isset($_SESSION['AOR1Selected'])) { $_SESSION['AOR1Selected'] = TRUE; } else { $_SESSION['AOR1Selected'] = FALSE; } break; default : $switchResult = FALSE; return $switchResult; break; } $switchResult = TRUE; return $switchResult; } function deleteFromArray(&$array, $deleteIt, $useOldKeys = FALSE) { $key = array_search($deleteIt,$array,TRUE); if($key === FALSE) { return FALSE; } unset($array[$key]); if(!$useOldKeys) { $array = array_values($array); } return $array; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/122695-why-doesnt-javascript-behave-take-two/#findComment-634527 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.