Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

(Noob Help) Passing/Reading Arrays 1

Status
Not open for further replies.

Codebunnie

Programmer
Mar 23, 2006
13
US
Hey all....
I am new to JavaScript, so bare with me on this. Im all googled out trying to figure out what is going on with this code.

I am trying to pass an array to a function and then output its contents, but I keep getting the term [object] or Undefined when the returned array is outputted.

Essentially, I want to take an array of input, and pass that info to another function for processing.

The code is for a form with checkboxes that a user searches content with. Each box represents a field to search on. All boxes are checked onLoad (requirement by client). The user then unchecks what they dont need. Once the form is submitted, I want to grab the checked boxes that they used, and redisplay them, so that the user knows what fields they searched on.

heres the code:

//remember all boxes are checked by default
var boxVal = new Array()

function findBoxes(){
var numOfBoxes = ""

numOfBoxes = document.forms.SearchQuery.Field.length //how many checkboxes do we have?
alert("Num of total Boxes is " + numOfBoxes)

for (i = 0; i < numOfBoxes; i++) { [highlight] //keep counting to get all the boxes [/highlight]
if( document.forms.SearchQuery.Field.checked) { [highlight]//but only find the boxes that are checked [/highlight]
boxVal= document.forms.SearchQuery.Field.value + " " [highlight] //set boxVal to the val of the checked box it found [/highlight]
alert("Checked Boxes are " + boxVal) [highlight] //Output the values to ensure that it works (which it does)[/highlight]
} }
return boxVal
}



function checkedBoxes(boxVal) {//
[highlight]//boxVal == Array of selected fields returned from findBoxes()[/highlight]
alert(boxVal) [highlight]//Output I get for this box is 'Undefined'[/highlight]
alert("value = " + document.forms.SearchQuery.Field.value) [highlight] //Output I get is 'Undefined'[/highlight]

[highlight]//if the values of the boxes passed from findBoxes() matches the values on the form
//set only those boxes to checked, and uncheck the rest (ones that do not match)[/highlight]

if (boxVal == document.forms.SearchQuery.Field.value)
{ document.forms.SearchQuery.Field.checked = true }
else
{ document.forms.SearchQuery.Field.checked = false } //end loop

} //End Function

[highlight]//findBoxes() is run onClick, checkedBoxes() runs onSubmit
//when checkedBoxes is called, the parameter passed is checkBoxes(this).[/highlight]

Any suggestions are greatly appreciated. Also, any suggestions on a different approach for this problem are welcome!
 
When you see 'undefined' it is because you are attempting to use a variable that has not been given any value.

When you see [object], it means that you are looking at the array itself and not the values IN the array. You would have to look at an index (myArray[index]) to see a specific value within. You would have to create a little routine if you wanted to show the contents of the whole array in a single alert message.

We will need to see more, however, to help you with this. We need to see, for example, HOW you use the call to checkedBoxes(...). If it is called onSubmit, then it's in the FORM tag, yes? And if you are sending the parameter 'this' as the argument, then 'this' is the whole form and you are overwriting boxVal.

Maybe I don't need to see more. Try this:
(1) keep the declaration of boxVal global.
(2) no need to "return boxVal" in findBoxes as the result is saved in the global variable
(3) make sure your onSubmit call to checkedBoxes() is in your FORM tag
(4) remove the parameter (sending and receiving) associated with checkedBoxes(); just use boxVal as you need to, it is there for you since it is a global variable.

Now, where you might still have a problem is with [red]document.forms.SearchQuery.Field.[/red]. I'd have to see your HTML to know what exactly is wrong here, but the general form of this type of statement is:

document.forms["formName"].elements["fieldName"]...

or

document.forms[variableWithFormNameAsItsValue].elements[differentVariableWithFormNameAsItsValue]...

Follow?

Dave

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...east is east and west is west and if you take cranberries and stew them like applesauce
they taste much more like prunes than rhubarb does
[infinity]
 
You haven't shown any code where you call the function to create the boxVal array, or what the form elements are. In the function that populates boxVal, you refer to document.forms.SearchQuery.Field as an array, but in your other function you refer to is as if it's a single element. You'll have to show more of the relevant code (we don't need to see your WHOLE page) to figure out what's going wrong for you.

Lee
 
Okay, taking the advice into account, i re-wrote some code in my Functions. But When the user submits the form, the value in BoxVal (the array of elements i am passing) gets reset to zero.

Also for boxVals, It seems as if it gets filled with the total amount of boxes, and only assigns values for those boxes that are checked. But i only want an array full of checked boxes, and I want that array to be passed and be available when the page loads after a search.

On initial load, i want all the boxes to be checked, and after that, i want it to record the previous boxes used to search, and output those as checked when the page reloads after the search.

I hope I am making sense..im sorry..lol

Here Ya Go..

function do_Onload() {
collectTablinks()
document.forms.SearchQuery.TypeSearch.value = 'documents'
expandContent(initialtab[1], tabobjlinks[initialtab[0]-1])
numOfTotalBoxes = document.forms.SearchQuery.Field.length
keepCheckedBoxes()
}

[highlight #7FFF00][/highlight]

var numOfTotalBoxes = "" [highlight #7FFF00] //Holds the total number of the boxes found on the form[/highlight]
var boxVals = new Array() [highlight #7FFF00] //Holds the actual values of the CHECKED boxes that are found[/highlight]

function findCheckedBoxes(){ [highlight #7FFF00]//Begin Function[/highlight]
alert("Function: FindCheckedBoxes:" + '\n \n' + " Num of total Boxes is " + numOfTotalBoxes)

for (i = 0; i < numOfTotalBoxes; i++) { [highlight #7FFF00] //keep counting to get all the boxes[/highlight]
if( document.forms.SearchQuery.Field.checked) { [highlight #7FFF00] //but only find the boxes that are checked [/highlight]
boxVals= document.forms.SearchQuery.Field.value + " " [highlight #7FFF00] //set boxVals to the val of the checked box it found[/highlight]
alert("DEBUG:::" + '\n' + "Function: FindCheckedBoxes: :" + '\n \n' + "Checked Boxes are " + boxVals)
} }
alert("DEBUG:::" + '\n' + "Function: FindCheckedBoxes :" + '\n \n' + "Number of array elements (Checked Boxes):" + boxVals.length)
[highlight #7FFF00]//DEBUG: User checks only two boxes, but the function returns a value of all the boxes on the form[/highlight]

return boxVals [highlight #7FFF00]//boxVal is now filled with the values for all the checked boxes on the form[/highlight]
} [highlight #7FFF00] //END Function[/highlight]


function keepCheckedBoxes(){ //Begin Function
alert("DEBUG:::" + '\n' + "Function: keepCheckedBoxes" + '\n \n' + "BoxVals.Length (Num of Array Elements Found)" + '\n \n' + boxVals.length) [highlight #7FFF00] // Should be 0 on initialLoad, [/highlight]
[highlight #7FFF00] //since boxVals is set in FindCheckedBoxes()[/highlight]

if (boxVals.length != 0){
for( x=0; x<= boxVals.length; x++) { [highlight #7FFF00] //begin For

alert(" DEBUG:::" + '\n' + "Function: keepCheckedBoxes :" + '\n \n' + boxVals)
[highlight #7FFF00]//if the values of the boxes passed from findBoxes() matches the values on the form [/highlight]
[highlight #7FFF00] //set only those boxes to checked, and uncheck the rest (ones that do not match) [/highlight]
if (boxVals[x] == document.forms.SearchQuery.Field.value)
{ document.forms.SearchQuery.Field.checked = true }
else
{ document.forms.SearchQuery.Field.checked = false }

}[highlight #7FFF00]//End For[/highlight]

} [highlight #7FFF00]//END If[/highlight]


else
[highlight #7FFF00] //If we dont get any vals from boxVals then check all boxes [/highlight]
{ [highlight #7FFF00]// Begin else[/highlight]
for(i=0; i< numOfTotalBoxes; i++){
document.forms.SearchQuery.Field.checked = "true"
} [highlight #7FFF00] //end for[/highlight]

} [highlight #7FFF00]//End else[/highlight]

} [highlight #7FFF00]//END FUNCTION[/highlight]








//----------------------------DOM CHECKS--------------------------------------------

//This loop checks to see what DOM version is being used and
//specifies event handling accordingly
//thus allowing the navigation menu to be cross browser compatible

if (window.addEventListener) //W3C DOM Implementation
// if window.addEventListener() is detected, pass the three parms that are
//necessary for the function to fire.
window.addEventListener("load", do_Onload, false)
else if (window.attachEvent)
// else if window.attachEvent() is detected, pass the two parms that are
//necessary for the function to fire.
window.attachEvent("onload", do_Onload) // IE DOM Implementation
else if (document.getElementById)
window.onload=do_Onload
</script>

<div>
<form NAME="SearchQuery" action="Directory2.asp" method="get" >
<!-- Create Tabs (And Set Hidden TabID via TypeSearch) -->
<input id= "TypeSearch" type ="hidden" name="TypeSearch">

<ul id="tablist">

<!-- TAB PARAMETERS -->
<li><a onclick=" expandContent('sc1', this); document.forms.SearchQuery.TypeSearch.value = 'Docs';">Docs</a></font></li>
<li><a onclick=" expandContent('sc2', this); document.forms.SearchQuery.TypeSearch.value = 'files'; ">Files</a></li>
<li><a onclick=" expandContent('sc3', this); document.forms.SearchQuery.TypeSearch.value = 'phoneNum'; ">Phone</a></li>
<li><a onClick=" expandContent('sc4', this); document.forms.SearchQuery.TypeSearch.value = 'MISC'; ">MISC</a></li>
</ul>


<!-- //////////////// Populate Tabs /////////////////////-->

<DIV id="tabcontentcontainer">

<table width="55%" border="0" bgcolor="1565ba" cellpadding="2" >
<tr>

<td>
<center>
<FONT SIZE=2 FACE="Arial" Color="FFFFFF"><b><i>Search!&nbsp&nbsp&nbsp </i></b></font>
<input TYPE="text" NAME="Pattern" id="SearchBox" Value="<%=request("Pattern")%>" SIZE="40" MAXLENGTH="40">
<input TYPE="Submit" Onclick="findCheckedBoxes();" Value="Submit" SIZE="25" >
</center></td>

</tr> </table>

<!-- ::: Documents Tab ::: -->
<div id="sc1" class="tabcontent">
<table width="55%" border="0" bgcolor="E5E5E5"> <!-- prev color e5e5e5 -->
<tr>
<td><center> <FONT FACE="ARIAL" SIZE="3" COLOR="Navy"> Title:
<input id="title" TYPE="checkbox" NAME="Field" disable Value="title"
<%iF instr(request("Field"), "title") > 0 THEN response.write "checked" %>>
</center></font></td>

<td><center>
<FONT FACE="ARIAL" SIZE="3" COLOR="Navy"> Scope:
<input id="scope" TYPE="checkbox" NAME="Field" VALUE="scope" disable
<%iF instr(request("Field"), "scope") > 0 THEN response.write "checked" %>>
</center></font></td>


<td><center>
<FONT FACE="ARIAL" SIZE="3" COLOR="Navy"> Objective:
<input id="objectives" TYPE="checkbox" NAME="Field" VALUE="objectives" disable
<%iF instr(request("Field"), "objectives") > 0 THEN response.write "checked" %>>
</center></font></td>

<td><center>
<FONT FACE="ARIAL" SIZE="3" COLOR="Navy"> Approach:
<input id="approach" TYPE="checkbox" NAME="Field" disable Value="approach"
<%iF instr(request("Field"), "approach") > 0 THEN response.write "checked" %>>
</center></font></td>

</tr></table>



</div>

<!-- ::: Files ::: -->
<div id="sc2" class="tabcontent">
<table width="55%" border="0" bgcolor="#FFFFFF"> <tr><td>&nbsp</td></tr></table>
</div>


<!-- ::: Phone Num Tab ::: -->
<div id="sc3" class="tabcontent">
<table width="55%" border="0" bgcolor="#FFFFFF"> <tr><td>&nbsp</td></tr></table>
</div>


<!-- ::: Misc Tab ::: -->
<div id="sc4" class="tabcontent">
<table width="55%" border="0" bgcolor="#FFFFFF"> <tr><td>&nbsp</td></tr></table>

</div>
</div><br></div></form>

<!-----:::::::::::::::::::::::::::::::::::::::::::::: END Search Navigation Bar Code:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::--->
 
Start by changing:

Code:
boxVals[i]=  document.forms.SearchQuery.Field[i].value + "  "

...to:

Code:
boxVals[[red]boxVals.length[/red]]=  document.forms.SearchQuery.Field[i].value + "  "

What YOU are doing is, for example, setting the boxVals[0] index to some value (assuming 0 is checked) and then, setting boxVals[8] to some values (assuming 8 is checked). Follow? This is because you are setting the same index (i) as the index of the box you're evaluating. boxVals.length, on the other hand, will always be the same as the next available index in boxVals. If you have 5 elements in boxVals, for example, they fill indeces 0 through 4. So the next index is 5 (also the current length of the array). See?

Fix that and then describe what problems you're still having.

Dave

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...east is east and west is west and if you take cranberries and stew them like applesauce
they taste much more like prunes than rhubarb does
[infinity]
 
I made the change you suggested. It works to get the checked boxes but doesnt get the values of the all the fields. For example, if the user checked 3 boxes, it will output the value of the first element in the array, and then undefined for the remaining two.

Also, my main problem is that boxVal seems to get set to zero on load.
 
boxVals is set to a new Array when the page loads, that is why it is empty. What are you after here?

Also, make sure your alert messages reflect the value you're trying to show. i is no good (for reasons we discussed above). boxVals.length is no good because you just changed the lenght. If you alert on the index [boxVals.length-1], that should show you the right value.

Dave

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...east is east and west is west and if you take cranberries and stew them like applesauce
they taste much more like prunes than rhubarb does
[infinity]
 
What I am After:

This is a search navigation form.
The form has four checkboxes which represent categories that the user can search on.

When the page first loads, all the checkboxes should be checked by default (this is what my client wants..i dunno why)

The user then unchecks any fields they do not want to search on, types something into the textbox, and hits submit.

What i need to do is, after the user submits the search, and the page reloads, instead of the values defaulting back to all checked boxes, I want them to see only the boxes they searched on previously. This lets the user know what previous query they submitted.

I figured that i could write a function that will grab the values from the form, store them in an array, and then pass those values to another function that is run when the page loads. If the value of boxVals is zero, then that means no boxes were checked, and this is the users first visit (so we check all the boxes for the default view). If the value of boxVals is not equal to zero, then take those values in that array, compare them to the values of the checkboxes on the form, and check only those.

Is that better? crap i even confuse myself with this. Sorry about that.
 
Is THIS page Dictionary.asp or does Dictionary.asp re-direct to this page after it is run?

Either way, all JavaScript variables are new when a page loads. You cannot maintain their values the way you are trying to do.

You can either set a cookie to remember which boxes are checked (probably not the way you want to go) or, when Dictionary.asp tells this page to load, have it send a message as to which check boxes to check (not unlike you must be telling the dictionary which boxes are checked).

--Dave

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...east is east and west is west and if you take cranberries and stew them like applesauce
they taste much more like prunes than rhubarb does
[infinity]
 
Nope, its not redirecting, and Nope, we cant use cookies. My teamate and I were looking at using an ASP session variable, but how would we set that session variable to the javascript array of boxVals?

Meaning, hows about we take the array boxVals and store it in the session variable to output on the next page?
 
Since your FORM's METHOD attribute is set to GET, are you finding that the values of the checked boxes are showing up in the URL of the re-loaded page? If so, you could grab them from there.

As for ASP session variables, I don't know about those (you could try the ASP Forum). However, since I'm certain it's a server-side variable, you can't get there from the JavaScript on this page unless you used it to send values to an ASP inside a hidden IFRAME and this ASP would then set the session variables.

Dave

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...east is east and west is west and if you take cranberries and stew them like applesauce
they taste much more like prunes than rhubarb does
[infinity]
 
Well the name for each textBox is Field, which is passed in the URL. We can grab the variable from the url, but Field appears more than once, if more than one checkbox is selected.

ie...URL:

How would i loop through with requestOf() for all values?
 
You can grab the URL with JavaScript as:

var myURL = document.location.href;

JavaScript's split() function will return an array, made out of parts of a string like:

var myURLParts = myURL.split("?");

All the stuff before the ? in the URL will be in index 0. All the stuff after in index 1.

var myURLParameters = myURLParts[1].split("&");

Now myURLParameters is an array of field/value pairs.

Code:
var myCheckboxNames = new Array();
for(var i=0; i<myURLParameters; i++)
{
 if(myURLParameters[i].indexOf("Field=") == 0)
  myCheckboxNames[myCheckboxNames.length] = myURLParameters[i].split("=")[1];
}

Can you see why all the names of your checked checkbox fields will now populate the array named myCheckBoxNames?

Now, if you just implement all this from the get-go, you might get a null when the page first loads.

When you get myURL, check it for a "?" before going on or else, when you try to access myURLParts[1], you'll get an error.

Does this make sense?

Dave

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...east is east and west is west and if you take cranberries and stew them like applesauce
they taste much more like prunes than rhubarb does
[infinity]
 
OK everything works ok....only one problem: (on checking the URL for a question mark)

if (fullURL.search("?")){ .....

or similarly:

if (fullURL.match("?")){ ....

give me unexpected quantifier errors...ugh. If i use other characters, it works though. It doesnt seem to like the "?
 
Codebunny, the methods search and match both expect a regexp as a parameter. If your string "?" is being treated as a regexp, then it's saying "match 0 or 1 instances of the preceding character (which is nothing as you have no characters in front of the ?)". To treat special characters as literal characters in a regexp you need to preface them with a backslash. So try this instead and see how it works for you (I'll give the example using proper regexp syntax):

Code:
if (fullURL.search([!]/\?/g[/!])) {

-or-

if (fullURL.match([!]/\?/g[/!])) {

Just a side note: Using search will return the index of the character found in the string, or -1 if it is not found. Match will return an array of matches of all ?'s found, or null if none are found. If you'd like to use a boolean method that will return true or false then you'll have to use the test method - which is a regexp method, not a string method - so you'll have to switch the order around in the call:
Code:
if (/\?/g.test(fullURL)) {

-kaht

[small] <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
[banghead] [small](He's back)[/small]
 
Codebunnie,

I'm not good with RegExp's (an unfulfilled New Year's resolution). When I suggested checking for the '?' in the URL, I was thinking more like:
Code:
if(fullURL.indexOf('?') > -1) [red]//then '?' is present[/red]

'hope that helps.

Dave

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...east is east and west is west and if you take cranberries and stew them like applesauce
they taste much more like prunes than rhubarb does
[infinity]
 
Thanx so much for all the help guys. I am now in the last stages of getting this all done, but now I am having difficulty comparing the two arrays. Ive tried a couple of different ways in looping and no dice. The highlighted loop is the one I have had the most luck in...the other commented out ones were where my logic led me.

Basically, if thirdsplit is empty, call checkAllBoxes,
if it isnt empty, then compare the elements in both arrays, and if they match, throw me an alertbox.

Code:
function do_Onload(){
collectTablinks()
document.forms.SearchQuery.TypeSearch.value = 'documents'   
expandContent(initialtab[1], tabobjlinks[initialtab[0]-1])
countBoxes()
urlSplit()
selectCheckBoxes()
}
   
//::::::::::::::::::::::::::::::::::::::::::::::::::::::
 
//This will be a 3 way split seperating the URL in three sections
//First Split: splitAtQuestionMark - seperates the URL @ "?"
//Second Split: splitAtAmpersand - seperates the elements @ "&Field" --leaves us with  = Value
//Third Split: splitAtEqual - seperates the field from the value @ "="
  
var thirdSplit = new Array()

function urlSplit(){ //BEGIN FUNCTION
 // 1. Get the URL of the current page. 
    var fullURL = document.location.href
//1.1 Check to make sure the URL has a ? for first split    
    if (/\?/g.test(fullURL)) {  
    
// 2. Split the full url at "?" to give us a two element array
     var firstSplit = fullURL.split(/\?/g)
// 3. Split the second element of the array @ "&"
     var secondSplit = firstSplit[1].split("&Field")
// 4. declare an array for the results from the third, and final split where the values of Field will be held
                    
//5.  Results from secondSplit will be Field = Value
//    Loop through the results from secondSplit
//    where the value of "Field=" is found
//    take the second element of the result from split it @ "=" 
//    set the result of that split to thirdSplit
//    return that value to be used by function SelectBoxes
     
alert ("DEBUG: Calling Function: urlSplit()")
alert ("DEBUG: Value of variables from urlSplit(): " + '\n\n' +  
      "fullUrl: " + fullURL  + '\n' +
      "firstSplit Sub Zero: " + '\n' + firstSplit[0] + '\n' + "firstSplit Sub One: "  + '\n' + firstSplit[1]  + '\n' +
      "secondSplit Sub Zero: "  + '\n' + secondSplit[0] + '\n'+ "secondSplit Sub One: " + '\n'  + secondSplit[1]  + '\n' )
                        
alert("DEBUG: index of secondSplit: " + secondSplit[1] + "length    " + secondSplit.length)
        
var x = secondSplit.length

      for (var y = 0; y< secondSplit.length; y++){
      alert("DEBUG: secondsplit sub " + y + '\n' + secondSplit[y] )
      }
          for( var i = 0; i<secondSplit.length; i++)
            {          
             thirdSplit[i] =  secondSplit[i].split("=") 
             }    
       alert(DEBUG: ThirdSplit Elements " + thirdSplit.length)
              for (var z = 0; z< thirdSplit.length; z++){
      		alert("DEBUG:thirdSplit sub " + z + '\n' + thirdSplit[z] )
      } return thirdSplit       }
     
      
/*  ------------------------------------------------ 
//orig code - replaced with what is above
  for( var i = 0; i<secondSplit; i++)
       {        
        if(secondSplit.indexOf("Field=") == 0)
         { thirdSplit[thirdSplit.length] = secondSplit[i].split("=") [1] } 
            }    
            alert(thirdSplit[i])
              return thirdSplit       }
            
            else { alert("No ? found") } 
-------------------------------------------------- */      
  }//END FUNCTION

  
function checkAllBoxes(){ //BEGIN FUNCTION
          var allBoxes = document.forms.SearchQuery.Field.length 
          var i = ""
                for( i = 0; i < allBoxes; i++)
                     {
                    alert("Calling Check All")
                    document.forms.SearchQuery.Field[i].checked = true
                    }
} //END FUNCTION

                    
var boxArray = new Array()
function countBoxes(){ // BEGIN FUNCTION
            var numOfBoxes = document.forms.SearchQuery.Field.length
            var i = ""      
            alert("Calling Count Boxes")                 
            for ( i = 0; i< numOfBoxes; i++)
            { 
             boxArray[i] = document.forms.SearchQuery.Field[i].value
      alert("Val Successfully  Passed Into Array  :" + '\n' +  boxArray[i])
            } 
            
            return boxArray
            
} //END FUNCTION
[highlight]   
function selectCheckBoxes(){ //BEGIN FUNCTION
            var i = ""    
            alert("Calling Select Check")
            alert(" VALS BEFORE LOOP:" + '\n\n' +  " ThirdSplit Array Length: " + thirdSplit.length + '\n' +
		 "  Box Array Length: " + boxArray.length)
            
                   
            if (thirdSplit.length != 0){
            
            
            for ( i in (thirdSplit && boxArray)) {
            alert("here") // <-- I get an alert here
             if(thirdSplit[i] == boxArray[i]){
             alert("here here")    //<-- But not here  
alert("Matching Values:  Third Split:"  
+ thirdSplit[i]
+ "Box Array: " 
+ boxArray[i] ) 
                                                    }
                        }
                        }
                
              else { alert("Intial Load of Page: thirdSplit = 0!")
                          checkAllBoxes() }
                          
                          
                          
                         
    } //END FUNCTION     [/highlight]                 

  
  
   
   /*     
    alert("Calling Select Check") 
    alert(" VALS BEFORE LOOP:" + '\n\n' + "ThirdSplit Array Length: " + thirdSplit.length + '\n' + 
	 "Box Array Length: " + boxArray.length)
  
    if (thirdSplit.length !=0){  
          for (var i = 0; i < boxArray.length; i++)
                for (var j = 0; j < thirdSplit.length; j++) 
                        if ( thirdSplit[j] == boxArray[i]){
                        alert("Match Found")  }
else  
              alert("Intial Load of Page: thirdSplit = 0!")
              checkAllBoxes()  
              
              }
    } //END FUNCTION            
   
   */   
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::
   
 /*
 
 
      if (thirdSplit.length != 0){
           alert("Oh bah!")
                          for( i in thirdSplit) 
                           alert(thirdSplit[i]) 
                                        for( z in boxArray)
                                        alert(boxArray[z]) 
                                                        if (thirdSplit[i] == boxArray[z]){
                                                             alert("Bah!")
                                                             alert("Matching Values:  Third Split:  "  + thirdSplit[i] + "Box Array: "  + boxArray[z] ) 
                                                         }                    
           
              else { alert("Intial Load of Page: thirdSplit = 0!")
                          checkAllBoxes() } 
                          }
   
   
    
 */
 
Start with this:

Change:
Code:
var firstSplit = fullURL.split(/\?/g)
to this:
Code:
var firstSplit = [!]unescape([/!]fullURL[!])[/!].split(/\?/g)

Your URL is being given standins for the ? and & (like you sometimes see &20 for a space). 'unescape' converts them back to the characters they represent.

Let us know what happens after that.

Dave

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...east is east and west is west and if you take cranberries and stew them like applesauce
they taste much more like prunes than rhubarb does
[infinity]
 
I made the change you suggested, and still the same thing happens. It gets to the alertBox ("here") and flashes it 3 times for the 3 (or however many times for the amount of elements in thirdSplit).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top