472,982 Members | 2,562 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

disable many input boxes

I have a form that contains 240 "products". Each Product has a TR. Each TR
contains a Yes and No radio button and a Product-Qty text input.

A situation exists where I have to go through all the products and check the
No radio button for all the products. In javascript, that is easy enough.

When the No radio button is clicked, I have to put '0' in the Product-Qty
text input, and disable the Product-Qty text input. I create an array of all
the html id's of all the Product-Qty text inputs, and iterate through the
array, setting the .disabled = true

var sProdCodeQtys = new Array();

// fill the sProdCodeQtys array with id's of the text input's

for (xxx= 0; xxx< sProdCodeQtys.length ; xxx++) {
var inputQty2 = document.getElementById(sProdCodeQtys[xxx]);
inputQty2.value = '0';
inputQty2.disabled = true;
}

This takes up to 30 seconds !! I'm dismayed it takes that long, anyone have
any better ideas ?

During the time it takes to do all this, I display the hourglass, but with
that length of time, it still looks like the browser has crashed.

Thanks,
Mike
Sep 6 '06 #1
6 2276
Mike wrote:
I have a form that contains 240 "products". Each Product has a TR. Each TR
contains a Yes and No radio button and a Product-Qty text input.

A situation exists where I have to go through all the products and check the
No radio button for all the products. In javascript, that is easy enough.

When the No radio button is clicked, I have to put '0' in the Product-Qty
text input, and disable the Product-Qty text input. I create an array of all
the html id's of all the Product-Qty text inputs, and iterate through the
array, setting the .disabled = true

var sProdCodeQtys = new Array();

// fill the sProdCodeQtys array with id's of the text input's

for (xxx= 0; xxx< sProdCodeQtys.length ; xxx++) {
var inputQty2 = document.getElementById(sProdCodeQtys[xxx]);
inputQty2.value = '0';
inputQty2.disabled = true;
}

This takes up to 30 seconds !! I'm dismayed it takes that long, anyone have
any better ideas ?
You could put a counter in your loop, like

counter++

And then do something like

document.forms[0].sometextbox.value
= 'now at ' + counter + ' of ' + sProdCodeQtys.length

Or perhaps a fancy progress bar with images, or table cells that swap
colour.

HTH

--
Bart

Sep 6 '06 #2

Bart Van der Donck wrote:
Mike wrote:
I have a form that contains 240 "products". Each Product has a TR. Each TR
contains a Yes and No radio button and a Product-Qty text input.

A situation exists where I have to go through all the products and check the
No radio button for all the products. In javascript, that is easy enough.

When the No radio button is clicked, I have to put '0' in the Product-Qty
text input, and disable the Product-Qty text input. I create an array of all
the html id's of all the Product-Qty text inputs, and iterate through the
array, setting the .disabled = true

var sProdCodeQtys = new Array();

// fill the sProdCodeQtys array with id's of the text input's

for (xxx= 0; xxx< sProdCodeQtys.length ; xxx++) {
var inputQty2 = document.getElementById(sProdCodeQtys[xxx]);
inputQty2.value = '0';
inputQty2.disabled = true;
}

This takes up to 30 seconds !! I'm dismayed it takes that long, anyone have
any better ideas ?
I'm no super-javascript developer, but Yikes!, that seems extreme no
matter what your code looks like.
>
You could put a counter in your loop, like

counter++

And then do something like

document.forms[0].sometextbox.value
= 'now at ' + counter + ' of ' + sProdCodeQtys.length

Or perhaps a fancy progress bar with images, or table cells that swap
colour.

HTH

--
Bart
I agree with Bart that using a method other than re-querying the length
of the array each time may help.

You may try something as simple as:

for (xxx= 0, yyy=sProdCodeQtys.length; xxx < yyy; xxx++) {
var inputQty2 = document.getElementById(sProdCodeQtys[xxx]);
inputQty2.value = '0';
inputQty2.disabled = true;
}

and see if that helps.

BTW, what have you done to test and see if that is the actual issue?
Are you sure the bottleneck isn't somewhere else?

Sep 6 '06 #3
Tom,
I have figured out that the loop I put in my message is what is taking all
the time. And it is actually setting the .disabled = false is what hogs the
time. If I comment that line out, all the text input fields get reset to 0
rather quickly...

Mike

"Tom Cole" <tc****@gmail.comwrote in message
news:11*********************@b28g2000cwb.googlegro ups.com...
>
Bart Van der Donck wrote:
>Mike wrote:
I have a form that contains 240 "products". Each Product has a TR. Each
TR
contains a Yes and No radio button and a Product-Qty text input.

A situation exists where I have to go through all the products and
check the
No radio button for all the products. In javascript, that is easy
enough.

When the No radio button is clicked, I have to put '0' in the
Product-Qty
text input, and disable the Product-Qty text input. I create an array
of all
the html id's of all the Product-Qty text inputs, and iterate through
the
array, setting the .disabled = true

var sProdCodeQtys = new Array();

// fill the sProdCodeQtys array with id's of the text input's

for (xxx= 0; xxx< sProdCodeQtys.length ; xxx++) {
var inputQty2 = document.getElementById(sProdCodeQtys[xxx]);
inputQty2.value = '0';
inputQty2.disabled = true;
}

This takes up to 30 seconds !! I'm dismayed it takes that long, anyone
have
any better ideas ?

I'm no super-javascript developer, but Yikes!, that seems extreme no
matter what your code looks like.
>>
You could put a counter in your loop, like

counter++

And then do something like

document.forms[0].sometextbox.value
= 'now at ' + counter + ' of ' + sProdCodeQtys.length

Or perhaps a fancy progress bar with images, or table cells that swap
colour.

HTH

--
Bart

I agree with Bart that using a method other than re-querying the length
of the array each time may help.

You may try something as simple as:

for (xxx= 0, yyy=sProdCodeQtys.length; xxx < yyy; xxx++) {
var inputQty2 = document.getElementById(sProdCodeQtys[xxx]);
inputQty2.value = '0';
inputQty2.disabled = true;
}

and see if that helps.

BTW, what have you done to test and see if that is the actual issue?
Are you sure the bottleneck isn't somewhere else?

Sep 6 '06 #4
ASM
Mike a écrit :
I have a form that contains 240 "products". Each Product has a TR. Each TR
contains a Yes and No radio button and a Product-Qty text input.

A situation exists where I have to go through all the products and check the
No radio button for all the products. In javascript, that is easy enough.
....
This takes up to 30 seconds !!
with IE probably ?
I'm dismayed it takes that long, anyone have
any better ideas ?
perhaps more efficient :
while you change your radio buttons you change also your text fields

function zeroing() {
// array of rows in form 'myForm'
var T = document.forms['myForm'].getElementsByTagName('TR');
for(var i=0;i<T.length;i++)
{
// array of inputs in each row
var C = T[i].getElementsByTagName('INPUT');
C[1].checked = true; // 2nd input is radio-button 'NO'
C[2].value = 0; // 3rd input is the text field
C[2].disabled = true;
}
}

--
Stephane Moriaux et son [moins] vieux Mac
Sep 6 '06 #5
Mike wrote:
I have a form that contains 240 "products". Each Product has a TR. Each TR
contains a Yes and No radio button and a Product-Qty text input.

A situation exists where I have to go through all the products and check the
No radio button for all the products. In javascript, that is easy enough.

When the No radio button is clicked, I have to put '0' in the Product-Qty
text input, and disable the Product-Qty text input. I create an array of all
the html id's of all the Product-Qty text inputs, and iterate through the
array, setting the .disabled = true

var sProdCodeQtys = new Array();

// fill the sProdCodeQtys array with id's of the text input's
Why not just generate the ID strings in the for loop below?

for (xxx= 0; xxx< sProdCodeQtys.length ; xxx++) {
Keep variables local unless there are good reasons to make them global.
It is also customary to use single digits for counters, usually 'i':

for (var i=0; i<sProdCodeQtys.length; i++) {

The use of a constant for sProdCodeQtys.length is recommended, though I
doubt you'll see a large speed improvement in this case.

var inputQty2 = document.getElementById(sProdCodeQtys[xxx]);
inputQty2.value = '0';
inputQty2.disabled = true;
}

This takes up to 30 seconds !! I'm dismayed it takes that long, anyone have
any better ideas ?
I suspect there is something seriously wrong elsewhere in your code.
The script below disables 240 text inputs in about 3 seconds using IE on
my ancient 500MHz PIII.

IE 5.2 on a similarly ancient Mac (400MHz G3) does it in about 1 second.
<title>Lists</title>
<script type="text/javascript">

function fixQty(el){
var name = 'qty-' + el.name.split('-')[1];
var textEl = el.form.elements[name];
if (el.checked && 'yes' == el.value){
textEl.disabled = false;
textEl.value = textEl.defaultValue;
return;
}
textEl.disabled = true;
textEl.value = 0;
}

function doAll(el){
var f = el.form;
var i=0;
var x;
while ( (x=f.elements['qty-' + i++]) ){
x.value = 0;
x.disabled = true;
}
}
</script>

<form action="">
<table>
<tr>
<td>
<input type="button" value="Disable all" onclick="doAll(this);">
<tr>
<td>
<input type="radio" name="rb-0" value="yes" checked
onclick="fixQty(this);">yes
<input type="radio" name="rb-0" value="no"
onclick="fixQty(this);">no<br>
<input type="text" name="qty-0" value="190">Quantity

<!-- Hack to generate HTML & not wast too much newsgroup bandwidth -->
<script type="text/javascript">
var theSource = [];
for (var i=1; i<240; i++){
theSource[theSource.length] = // Array.push not supported in IE 5.2
'<tr><td>'
+ '<input type="radio" name="rb-' + i + '" value="yes" checked '
+ 'onclick="fixQty(this);">yes'
+ '<input type="radio" name="rb-' + i + '" value="no"'
+ 'onclick="fixQty(this);">no<br>'
+ '<input type="text" name="qty-' + i + '" value="190">Quantity';
}
document.write( theSource.join('') );
</script>
</table>
</form>

--
Rob
Sep 7 '06 #6
JRS: In article <Tq******************************@skypoint.com>, dated
Wed, 6 Sep 2006 10:52:40 remote, seen in news:comp.lang.javascript, Mike
<mb*****@skypoint.composted :
>
This takes up to 30 seconds !!
While that does sound long, the statement is of little real value
without at least some description of the browser and the machine it is
running on.

I know of two ways to indicate progress :-

Writing to window.status - easy, deprecated, but generally harmless; may
not always work.

Reconfiguring your process to run for, say, a second then write the
progress, set a timeout to restart the process, and return. The update
will become visible while the process is inactive, and remain so.

It's a good idea to read the newsgroup and its FAQ.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Sep 7 '06 #7

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

Similar topics

2
by: Joey | last post by:
Say a customer inserts into a sql database field (NUMINSERTS) the number 6. On the following page, I want to build a table that displays 6 input boxes, since the customer said they wanted 6 text...
3
by: KathyB | last post by:
Hi, I'm trying to find a way to validate input text boxes where I don't know the names until the page is rendered. I've got 2 validate functions that fire with the onsubmit button of a "mini" form...
12
by: Forti2ude | last post by:
Hello, I have a simple form... <form> <select name="foo" multiple> <option value="1">one</option> <option value="2">two</option> <option value="3">three</option> </select>
9
by: Marc | last post by:
Okay, here's the problem - I have 3 radio buttons, and 11 check boxes (which are disabled by default). I have the javascript below which when the last radio button is clicked, enables the...
3
w33nie
by: w33nie | last post by:
I want to disable the text boxes, captain_name and captain_email, but only if the radio button, captain_guarantee, has NOT been checked. how do i do this? <form name="formTeamApplication"...
2
by: windandwaves | last post by:
Hi Folk I have a form with the following structure: <form onsubmit="getsearchdata();"> lots of input boxes here <input type="submit" name="submit" onsubmit="getsearchdata();"> </form> In...
1
by: Plissskin | last post by:
I would like to put radio buttons (check boxes, drop down lists) in an ItemTemplate field and have them disabled so the user is not confused. However, I do not like simply disabling the controls...
3
hsriat
by: hsriat | last post by:
How can I temporarily disable vertical scrollbar? I have replaced confirmation boxes and alert boxes with inlay popup DIVs. But while they are on the screen, I need to disable scrollbar of the...
1
by: rash007 | last post by:
I am building up a table in php built from an array in a database. I can assign each row its own id's etc. But I need to enable or disable checkbox buttons and a text area depending on the checkbox...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.