Should I loop

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve Bishop

    Should I loop

    I have 10 fields each with it's own row in a table. Based on another
    fields value within the same row for each, I would like to hide or show
    the row.

    Example: I have 10 rows with size and order qty data:
    Row 1 thru 4 are taken with sizes large, X-Large, XX-Large and
    XXX-Large.

    Rows 5 thru 10 don't have size values populated, so I want to hide the
    row. I know how to show and hide elements by id including TR's, but I
    was wondering if there is an efficient way to use a loop for this vs.
    using a big ass IF statement. Help/Examples appreciated. Thanks.



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
  • Brian Genisio

    #2
    Re: Should I loop

    Steve Bishop wrote:
    [color=blue]
    > I have 10 fields each with it's own row in a table. Based on another
    > fields value within the same row for each, I would like to hide or show
    > the row.
    >
    > Example: I have 10 rows with size and order qty data:
    > Row 1 thru 4 are taken with sizes large, X-Large, XX-Large and
    > XXX-Large.
    >
    > Rows 5 thru 10 don't have size values populated, so I want to hide the
    > row. I know how to show and hide elements by id including TR's, but I
    > was wondering if there is an efficient way to use a loop for this vs.
    > using a big ass IF statement. Help/Examples appreciated. Thanks.
    >[/color]

    You really need to show code, so I will need to make assumptions...

    assuming that the data is in an array myArray. Since I dont know what
    type of data you have in the array, I am assuming it is cell data.
    ////////////////////////////////////
    for(i=0; i<myArray.lengt h; i++)
    {
    if(myArray[i].innerText == "")
    // hide
    else
    // dont hide
    }
    ////////////////////////////////////

    If you need anything more specific, you will _have_ to give us example
    code to modify.

    Brian

    Comment

    • Steve Bishop

      #3
      Re: Should I loop

      Thanks Brian. Help appreciated. This is embarrassing, but here I go:
      if (myform2.itm_00 5.value == "")
      {
      document.getEle mentById("q5"). style.visibilit y="hidden"
      document.getEle mentById("q6"). style.visibilit y="hidden"
      document.getEle mentById("q7"). style.visibilit y="hidden"
      document.getEle mentById("q8"). style.visibilit y="hidden"
      document.getEle mentById("q9"). style.visibilit y="hidden"
      document.getEle mentById("q10") .style.visibili ty="hidden"
      }
      if (myform2.itm_00 6.value == "")
      {
      document.getEle mentById("q6"). style.visibilit y="hidden"
      document.getEle mentById("q7"). style.visibilit y="hidden"
      document.getEle mentById("q8"). style.visibilit y="hidden"
      document.getEle mentById("q9"). style.visibilit y="hidden"
      document.getEle mentById("q10") .style.visibili ty="hidden"
      }
      if (myform2.itm_00 7.value == "")
      {
      document.getEle mentById("q7"). style.visibilit y="hidden"
      document.getEle mentById("q8"). style.visibilit y="hidden"
      document.getEle mentById("q9"). style.visibilit y="hidden"
      document.getEle mentById("q10") .style.visibili ty="hidden"
      }
      if (myform2.itm_00 8.value == "")
      {
      document.getEle mentById("q8"). style.visibilit y="hidden"
      document.getEle mentById("q9"). style.visibilit y="hidden"
      document.getEle mentById("q10") .style.visibili ty="hidden"
      }
      if (myform2.itm_00 9.value == "")
      {
      document.getEle mentById("q9"). style.visibilit y="hidden"
      document.getEle mentById("q10") .style.visibili ty="hidden"
      }
      if (myform2.itm_01 0.value == "")
      {
      document.getEle mentById("q10") .style.visibili ty="hidden"
      }


      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      • Brian Genisio

        #4
        Re: Should I loop

        Steve Bishop wrote:
        [color=blue]
        > Thanks Brian. Help appreciated. This is embarrassing, but here I go:
        > if (myform2.itm_00 5.value == "")
        > {
        > document.getEle mentById("q5"). style.visibilit y="hidden"
        > document.getEle mentById("q6"). style.visibilit y="hidden"
        > document.getEle mentById("q7"). style.visibilit y="hidden"
        > document.getEle mentById("q8"). style.visibilit y="hidden"
        > document.getEle mentById("q9"). style.visibilit y="hidden"
        > document.getEle mentById("q10") .style.visibili ty="hidden"
        > }[/color]

        <SNIP>....
        [color=blue]
        > if (myform2.itm_01 0.value == "")
        > {
        > document.getEle mentById("q10") .style.visibili ty="hidden"
        > }
        >[/color]

        Assuming you know the number of total lines (number_of_cell s) ... I am
        short-circuiting it. I am also assuming you index 1 to 10, instead of 0
        to 10 I havent tested this, so there may be typos or something, but you
        will get the idea...

        Oh yeah, this also assumes a broser that uses getElementById. Older
        browsers may need some other method...

        Also note, that your method for making things hidden will not work on
        all browsers.

        ////////////////////////////////////////////////
        var number_of_cells = 10;

        for(i=1; i<=number_of_ce lls; i++) {
        if(document.get ElementById("it m_" + i).value == "")
        document.getEle mentById("q" + i).style.visibi lity="hidden";
        }
        /////////////////////////////////////////////////


        Comment

        Working...