473,503 Members | 4,234 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Velocita di getElementById

Ciao a tutti,

sto sviluppando una jsp che mostra all'utente una serie di celle sulle
quali ad ogni
evento onclick() eseguo la routine SelezionaSpazio passando gli id sia
della cella
che dei livelli superiodi di raggruppamento su cui ad ogni click devo
sommare o
sottrarre 1.

Il colore della cella deve cambiare inoltre da coloreOn a coloreOff. Le
celle sulla pagina sono in media di 300.

Secondo voi, calcolando che ad
ogni click devo modificare anche dei campi hidden, č corretto il mio
modo di accedere ai singoli elementi dell'HTML???

Esistono modi per accedere alle variabili HTML in modo piu rapido?

Grazie

//************************************************** ***************************//

function selezionaSpazio(idtabe, idcomune, idstrada, colorOn,
colorOff) {

// Verifico che lo spazio sia selezionabile
var selezionabile = document.getElementById('slz' + idtabe);
if (selezionabile.value == 'S') {

var calledByScript = arguments[1];
var tabe = document.getElementById('tbl' + idtabe);
var sceltoComune = document.getElementById('slc' + idcomune);
var sceltoStrada = document.getElementById('sls' + idstrada);
var scelta = document.getElementById('ssp' + idtabe);
//var scelta = document.getElementByName('SELSPEJ' + idtabe);
var prezzo = document.getElementById('prs' + idtabe);

var valorePre = document.getElementById('valpre');

var immagscelta = document.getElementById('bas' + idtabe);

var immagopzione = document.getElementById('bal' + idtabe);
var opzione = document.getElementById('opz' + idtabe);

document.JPRE02.SAVPAGJ.value = 'N';

if (!tabe) return;
if (scelta.value != 'S') {
tabe.bgColor = colorOn;
tabe.title = 'Spazio prenotato';
sceltoComune.value = Number(sceltoComune.value)+ 1;
sceltoStrada.value = Number(sceltoStrada.value)+ 1;
scelta.value = "S";
immagscelta.src='../gif/led-red.gif';
immagscelta.alt='Spazio selezionato';
valorePre.value = parseFloat(valorePre.value) +
parseFloat(prezzo.value);
}
else {
tabe.bgColor = colorOff;
tabe.title = 'Spazio non prenotato';
sceltoComune.value = Number(sceltoComune.value)- 1;
sceltoStrada.value = Number(sceltoStrada.value)- 1;
scelta.value = "N";
immagscelta.src='../gif/led-gray.gif';
immagscelta.alt='Seleziona Spazio';
immagopzione.src='../gif/led-gray.gif';
opzione.value = 'N';
immagopzione.alt='Opziona Spazio';
valorePre.value = parseFloat(valorePre.value) -
parseFloat(prezzo.value);
}

//if (!calledByScript) saveCategState();

// Verifico se lo spazio era gia venduto
var giavenduto = document.getElementById('gvn' + idtabe);
if (giavenduto.value == 'S') {
tabe.bgColor = '#CCCCCC';
tabe.title = 'Spazio venduto';
selezionabile.value = 'N'
immagscelta.src='../gif/led-red.gif';
}

}

}

//************************************************** ***************************//

May 22 '06 #1
2 1250
JRS: In article <11*********************@i39g2000cwa.googlegroups. com>,
dated Mon, 22 May 2006 04:41:23 remote, seen in
news:comp.lang.javascript, lorologiodoro <cm******@gmail.com> posted :
Esistono modi per accedere alle variabili HTML in modo piu rapido?
function selezionaSpazio(idtabe, idcomune, idstrada, colorOn,
colorOff) {

// Verifico che lo spazio sia selezionabile
var selezionabile = document.getElementById('slz' + idtabe);
AIUI, that must search through all the IDs until it finds the one
wanted. Possibly, if you can put all those elements in a Form, and
identify the form as (effectively) var F = this.form, you can address
the elements within the form and search only within the form. Newsgroup
FAQ & FAQ notes may help.

Also, you could do some of the lookups in onLoad code, and store the
references in global variables for use later - e.g. valorePre.

sceltoComune.value = Number(sceltoComune.value)+ 1;
General : with S a string, +S should be faster than Number(S) + 1.
Particular : How about sceltoComune.value++ ??

valorePre.value = parseFloat(valorePre.value) +
parseFloat(prezzo.value);


Likewise, faster,
valorePre.value = +valorePre.value + +prezzo.value ;

Don't let your posting agent line-wrap code; posted code should be
directly executable. Indent with two or three spaces.

I regret to say that there's only one thing I can write in Italian; I
don't know exactly what it means, but it seems irrelevant here.

--
© 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.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
May 22 '06 #2
hi,
thank you for your help...
my IDs are already putted in a form ...

what do you mean when you talk about form? ... do you mean that the
variable value returns faster if i use document.form.SELEZI.value in
stead of getelementbyID?

on your opinion how could i store values in global variables in the
onLoad code? ... how can i update HTML variables from global variables?
....

thank you
and...
sorry for my poor english! :)

May 23 '06 #3

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

Similar topics

1
2685
by: lawrence | last post by:
This PHP function prints out a bunch of Javascript (as you can see). This is all part of the open source weblog software of PDS (www.publicdomainsoftware.org). We had this javascript stuff...
12
3867
by: lawrence | last post by:
The following function correctly makes everything invisible but then fails to turn the one chosen DIV back to visible. I imagine I'm getting the syntax of the variable wrong? I've tried this with...
4
5436
by: lawrence | last post by:
Can anyone tell me why this code works in Netscape 7.1 but not in IE??? <SCRIPT type='text/javascript'> function makeVisible(nameOfDiv) {...
7
5961
by: PaulB | last post by:
Good Morning everybody, I'm trying to adapt a tutorial script that will handle the behaviour of an "Expanding/Contracting" site-navigation menu. The code that seems to handle the expansion and...
3
9241
by: davidkarlsson74 | last post by:
Error: document.getElementById("folderMenu").cells has no properties File: http://www.volkswagen.se/tillbehor/js/foldermenu.js Rad: 49 The function activates different DIV:s, but doesn't seem to...
1
36504
by: Andre Ranieri | last post by:
Hello, I'm trying to set up an ASP.NET 2.0 form where the user enters values in WebControls.TextBoxes for amount owing, interest and late fees and a JavaScript function totals the three values...
4
2605
by: dr1ft3r | last post by:
Hey guys, I'm building a site for a landscaping business down the street and can't seem to get part of the code functioning correctly. The code fails on line 68 where I make a reference to an...
13
4913
by: RommelTJ | last post by:
Hi, My website (http://www.justiceinmexico.org/indextest.php) looks good in Firefox, but horrible in IE, and I think it's because of an error in the javascript of a free web ticker I got off the...
5
5750
by: jhappeal | last post by:
I do not know Javascript that well so I might be going about this the wrong way. Any help would be appreciated. This function attempts to hide the options inside of the optgroup tag of the second...
0
7264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6975
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5562
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
371
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.