473,382 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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!
Jul 20 '05 #1
3 1856
Steve Bishop wrote:
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.


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.length; 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

Jul 20 '05 #2
Thanks Brian. Help appreciated. This is embarrassing, but here I go:
if (myform2.itm_005.value == "")
{
document.getElementById("q5").style.visibility="hi dden"
document.getElementById("q6").style.visibility="hi dden"
document.getElementById("q7").style.visibility="hi dden"
document.getElementById("q8").style.visibility="hi dden"
document.getElementById("q9").style.visibility="hi dden"
document.getElementById("q10").style.visibility="h idden"
}
if (myform2.itm_006.value == "")
{
document.getElementById("q6").style.visibility="hi dden"
document.getElementById("q7").style.visibility="hi dden"
document.getElementById("q8").style.visibility="hi dden"
document.getElementById("q9").style.visibility="hi dden"
document.getElementById("q10").style.visibility="h idden"
}
if (myform2.itm_007.value == "")
{
document.getElementById("q7").style.visibility="hi dden"
document.getElementById("q8").style.visibility="hi dden"
document.getElementById("q9").style.visibility="hi dden"
document.getElementById("q10").style.visibility="h idden"
}
if (myform2.itm_008.value == "")
{
document.getElementById("q8").style.visibility="hi dden"
document.getElementById("q9").style.visibility="hi dden"
document.getElementById("q10").style.visibility="h idden"
}
if (myform2.itm_009.value == "")
{
document.getElementById("q9").style.visibility="hi dden"
document.getElementById("q10").style.visibility="h idden"
}
if (myform2.itm_010.value == "")
{
document.getElementById("q10").style.visibility="h idden"
}
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3
Steve Bishop wrote:
Thanks Brian. Help appreciated. This is embarrassing, but here I go:
if (myform2.itm_005.value == "")
{
document.getElementById("q5").style.visibility="hi dden"
document.getElementById("q6").style.visibility="hi dden"
document.getElementById("q7").style.visibility="hi dden"
document.getElementById("q8").style.visibility="hi dden"
document.getElementById("q9").style.visibility="hi dden"
document.getElementById("q10").style.visibility="h idden"
}
<SNIP>....
if (myform2.itm_010.value == "")
{
document.getElementById("q10").style.visibility="h idden"
}


Assuming you know the number of total lines (number_of_cells) ... 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_cells; i++) {
if(document.getElementById("itm_" + i).value == "")
document.getElementById("q" + i).style.visibility="hidden";
}
/////////////////////////////////////////////////
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Xavier Decoret | last post by:
for (int i=0;i<10;++i) { int i = -1; cout<<i<<endl; } As far as I understand, the int declaration in the for statement makes it declared for the scope of the for loop. So it would not be...
8
by: Chris Mayers | last post by:
I am trying to track a suspected memory leak in an application I'm writing and through repeated simplification of my project, I have found the following which is quite easily replicated should you...
8
by: Bshealey786 | last post by:
Okay im doing my final project for my first computer science class(its my major, so it will be my first of many), but anyway im a beginner so im not to great with C++ yet. Anyway this is the error...
17
by: SUMIT | last post by:
I wrote a program for removing comment from C source file for which i... 1.first constructed a DFA 2.used goto statement to write a program. now it was very easy to model DFA using goto & i...
12
by: melanieab | last post by:
Hi, I'm trying to check and see if something other than numbers (either the +, -, *, or /) are entered into a textbox, where bigR is what I call the text in the textbox. I can get what was...
12
by: ryann18 | last post by:
1. Write a while loop that verifies that teh user enters a positive integer value. 2. Write a do loop that verifies that teh user enters an even integer value. 3. Write a for loop to print...
3
by: assgar | last post by:
Hi I thought I had resolved this problem but I am intermittently the receving the warnings below. This code consist of a 1) HTML form, 2) a display function on the HTML form and 3) a...
7
by: UnkleVo | last post by:
Can someone run the code below and tell me why it never reaches 0.06? I am really puzzled..... or just going crazy? Dim i As Double For i = 0.01 To 0.05 Step 0.01 Debug.WriteLine(i) Next...
2
by: gm04030276 | last post by:
hey, i'm basically trying to use php sessions and a bit of javascript to make tabbed browsing within a web page using sessions to store the data of the different opened pages. Problem: when i unset...
3
by: Rudi | last post by:
Hello, following problem: At program end or release an assembly a serial device should get a final exit sequence. How can I do this? With Dispose() it's no problem, but this assembly is used...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.