Web Analytics Made Easy -
StatCounter Arrays - CodingForum

Announcement

Collapse
No announcement yet.

Arrays

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Arrays

    Hi all - i'm a javascript novice trying to either hide or show a load of HTML table rows - but this is difficult for me as the IDs of the table rows are in an array. The code that I've used so far is as follows, but this doesn't show and hide the rows because it doesn't involve any arrays - so this code only works when there is only one table row in the array - please help!

    <SCRIPT language="javascript">
    function expand(oObject) {
    strID = oObject.id
    strSRC= oObject.src
    strTRDATA = ""

    //alert (strID)
    //alert (strID.slice(3))
    strTRDATA = (strTRDATA.concat("tr",strID.slice(3), "Data"))
    //alert (strTRDATA)

    if(strSRC.search("SectionCollapse.gif") !=-1) {
    document.all(strTRDATA).style.display="Block"
    oObject.src="/ACR.nsf/SectionExpand.gif?OpenImageResource"
    }
    else {
    document.all(strTRDATA).style.display="none"
    oObject.src="/ACR.nsf/SectionCollapse.gif?OpenImageResource"
    }
    }
    </SCRIPT>

  • #2
    Do you have access to the array (read/modify)? Is the table already created and you just need to hide/show different rows?

    Comment


    • #3
      thanks for replying tamienne - the table is built - all of the rows have the same ID and therefore (i believe) all stored in an array - i just need to be able to manipulate the array with JS so as to hide/show the rows in the array. Thanks

      Comment


      • #4
        I'm sorry..i'm still not completely understanding what you have to work with.

        What does the array and table look like?

        Comment


        • #5
          Hi

          perusing on the fly, the first thing I notice is the use of concat: it wants Array arguments: that is:

          anArray.concat(anotherArray, anotherArray, anotherArray)

          also, it requires you to assign the main array as the object which has to be transformed, for (strangely enough) concat doesn't appear as direxctly affecting the object but... returning a NEW one! So:

          anArray=anArray.concat(anotherArray, anotherArray, anotherArray)

          This also means strTRDATA must be an array, not a string, and also its arguments.
          this may probably solve at least one of the potential issues

          ciao
          Alberto http://www.unitedscripters.com/

          Comment

          Working...
          X