473,698 Members | 2,187 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.getEle mentById('slz' + idtabe);
if (selezionabile. value == 'S') {

var calledByScript = arguments[1];
var tabe = document.getEle mentById('tbl' + idtabe);
var sceltoComune = document.getEle mentById('slc' + idcomune);
var sceltoStrada = document.getEle mentById('sls' + idstrada);
var scelta = document.getEle mentById('ssp' + idtabe);
//var scelta = document.getEle mentByName('SEL SPEJ' + idtabe);
var prezzo = document.getEle mentById('prs' + idtabe);

var valorePre = document.getEle mentById('valpr e');

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

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

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

if (!tabe) return;
if (scelta.value != 'S') {
tabe.bgColor = colorOn;
tabe.title = 'Spazio prenotato';
sceltoComune.va lue = Number(sceltoCo mune.value)+ 1;
sceltoStrada.va lue = Number(sceltoSt rada.value)+ 1;
scelta.value = "S";
immagscelta.src ='../gif/led-red.gif';
immagscelta.alt ='Spazio selezionato';
valorePre.value = parseFloat(valo rePre.value) +
parseFloat(prez zo.value);
}
else {
tabe.bgColor = colorOff;
tabe.title = 'Spazio non prenotato';
sceltoComune.va lue = Number(sceltoCo mune.value)- 1;
sceltoStrada.va lue = Number(sceltoSt rada.value)- 1;
scelta.value = "N";
immagscelta.src ='../gif/led-gray.gif';
immagscelta.alt ='Seleziona Spazio';
immagopzione.sr c='../gif/led-gray.gif';
opzione.value = 'N';
immagopzione.al t='Opziona Spazio';
valorePre.value = parseFloat(valo rePre.value) -
parseFloat(prez zo.value);
}

//if (!calledByScrip t) saveCategState( );

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

}

}

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

May 22 '06 #1
2 1258
JRS: In article <11************ *********@i39g2 000cwa.googlegr oups.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.getEle mentById('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.va lue = Number(sceltoCo mune.value)+ 1;
General : with S a string, +S should be faster than Number(S) + 1.
Particular : How about sceltoComune.va lue++ ??

valorePre.value = parseFloat(valo rePre.value) +
parseFloat(pre zzo.value);


Likewise, faster,
valorePre.value = +valorePre.valu e + +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.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.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.S ELEZI.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
2698
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 working, but it only worked for IE. You can see a working version here: http://www.publicpen.com/designer/mcControlPanel.php username: designer password: designer123 However, I've tried to rewrite this so it would work in all browsers,
12
3927
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 both single quotes and no single quotes, but it doesn't work either way. What am I doing wrong? <SCRIPT type='text/javascript'> function makeVisible(nameOfDiv) { document.getElementById('weblogs').style.visibility='hidden';
4
5473
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) { document.getElementById(nameOfDiv).style.visibility='visible'; document.getElementById(nameOfDiv).style.height='auto'; if (nameOfDiv != 'weblogs')
7
5988
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 contraction follows at the bottom of my message here. This following line is a big part of my hang-up: document.getElementById('m1').style.display='none';
3
9264
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 work on FireFox or Netscape. What could be wrong? The function: function setActiveTab(tabNo) {
1
36517
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 and sets the value of a label (lblTotal) to the sum of the three textbox values. The form is in a content place holder. I've added the following block of code in my form load.
4
2638
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 iframe's src property. Being that IE does not follow standard and considers an id, name, etc as a qualifying identifier for the document.getElementById object, I double checked to make sure that there's only one instance of id = "servif" and I never use...
13
4941
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 internet. When I run Firebug on it, it says: document.getElementById("TICKER") has no properties TICKER_CONTENT = document.getElementById("TICKER").innerHTML; Here is the complete script:
5
5763
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 select box based on the user selected option of the first select box. It works fine in Mozilla but IE7 still shows all the optgroups in the second select box. The idea is to show the appropriate list of states based on what country a user selects...
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9170
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8901
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5862
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4371
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
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 we have to send another system
3
2007
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.