By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,636 Members | 1,189 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,636 IT Pros & Developers. It's quick & easy.

disable many input boxes

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a

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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.