473,811 Members | 3,811 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

if getElementById && getElementById?

chunk1978
224 New Member
can someone please tell me what is wrong with this function's syntax? it's not working for me...

Expand|Select|Wrap|Line Numbers
  1. if (document.getElementById('DIVinvoicesubtotal').style.display = 'none' && document.getElementById('DIVgst').style.display = 'none' && document.getElementById('DIVqst').style.display = 'none' && document.getElementById('DIVhst').style.display = 'none';) {
  2.     form.invoicesubtotal.value="";
  3.     form.gst.value="";
  4.     form.qst.value="";
  5.     form.hst.value="";
  6.     form.invoicetotal.value = '$' + addCommas(invoicesubtotalVAR.toFixed(2)) + ' CAD';}
  7.  
  8.     if (document.getElementById('DIVinvoicesubtotal').style.display = 'block' && document.getElementById('DIVgst').style.display = 'block' && document.getElementById('DIVqst').style.display = 'none' && document.getElementById('DIVhst').style.display = 'none';) {
  9.     form.invoicesubtotal.value = '$' + addCommas(invoicesubtotalVAR.toFixed(2)) + ' CAD';
  10.     form.gst.value = GST.toFixed(2);
  11.     form.qst.value="";
  12.     form.hst.value="";
  13.     form.invoicetotal.value = '$' + addCommas(SUBTOTALandGST.toFixed(2)) + ' CAD';}
  14.  
is it not possible to write my "if" statement this way? or should it be something like:

if (document.getEl ementById('DIVi nvoicesubtotal' ).style.display ='block'=True

thanks in advance
Feb 9 '07 #1
7 8458
dmjpro
2,476 Top Contributor
look ...
if u write if(i =5)
the condition is always true because the statement will be ...
if(i) that is ... if(5)
u r assigning the 5 to i.
but to check the value of i whether it is 5 or anything else..
try write ...
if(i == 5)...
it will work
Feb 9 '07 #2
chunk1978
224 New Member
look ...
if u write if(i =5)
the condition is always true because the statement will be ...
if(i) that is ... if(5)
u r assigning the 5 to i.
but to check the value of i whether it is 5 or anything else..
try write ...
if(i == 5)...
it will work
excusé-moi?

nope... simply adding two equal signs didn't work... i think i tried that 18 times before posting... here's an example of something that works:

Expand|Select|Wrap|Line Numbers
  1.     if (document.getElementById('DIVinvoicesubtotal').style.display = 'none' ) {
  2.     form.invoicesubtotal.value="";
  3.     form.gst.value="";
  4.     form.qst.value="";
  5.     form.hst.value="";
  6.     form.invoicetotal.value = '$' + addCommas(invoicesubtotalVAR.toFixed(2)) + ' CAD';}
  7.  
however, the following DOESN'T work

Expand|Select|Wrap|Line Numbers
  1.     if (document.getElementById('DIVinvoicesubtotal').style.display = 'none' && document.getElementById('DIVgst').style.display = 'none' && document.getElementById('DIVqst').style.display = 'none' && document.getElementById('DIVhst').style.display = 'none';) {
  2.     form.invoicesubtotal.value="";
  3.     form.gst.value="";
  4.     form.qst.value="";
  5.     form.hst.value="";
  6.     form.invoicetotal.value = '$' + addCommas(invoicesubtotalVAR.toFixed(2)) + ' CAD';}
  7.  
so the problem seems to be with adding multiple conditions using "&&" between the numerous "...style.displ ay='none'"...

the mystery continues...
Feb 9 '07 #3
dorinbogdan
839 Recognized Expert Contributor
It should work if:
1. use == instead of =
2. remove the semi-colon ( ; ) inside of the if conditon (after last 'none').
Feb 9 '07 #4
dorinbogdan
839 Recognized Expert Contributor
Also, separate each of the 3 conditions with paranthesis, like.
Expand|Select|Wrap|Line Numbers
  1. if ((x == 'none') && (y == 'none') && (z == 'none'))
If still fails, please include more sample code, if possible, and I'll try out locally.
Feb 9 '07 #5
chunk1978
224 New Member
It should work if:
1. use == instead of =
2. remove the semi-colon ( ; ) inside of the if conditon (after last 'none').
THANK YOU! seems to work now! it's strange how using one equal sign works if there only one condition, but it requires two equal signs if there are more, as well as that silly semi-colon (can't believe i missed the semi-colon)...

you've made my day ;-)
Feb 9 '07 #6
acoder
16,027 Recognized Expert Moderator MVP
THANK YOU! seems to work now! it's strange how using one equal sign works if there only one condition, but it requires two equal signs if there are more, as well as that silly semi-colon (can't believe i missed the semi-colon)...

you've made my day ;-)
One equal sign works for one condition because it is setting instead of comparing so it will always be true. Always use double equals for comparing.
Feb 9 '07 #7
acoder
16,027 Recognized Expert Moderator MVP
Also, separate each of the 3 conditions with paranthesis, like.
Expand|Select|Wrap|Line Numbers
  1. if ((x == 'none') && (y == 'none') && (z == 'none'))
If still fails, please include more sample code, if possible, and I'll try out locally.
btw, dorin, thanks for helping out. It's nice when people help out, especially new members.
Feb 9 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2174
by: Adam | last post by:
I have a scrollbar that runs at the top of my page, I have it in a external js file and call it in the head tags of the webpage code. can you one tell me how to get this code to work with other browsers mainly Netscape 7 and above. Currently it doesn't display. this is the scroll bar code Thanks ----------------------------------------------------------------------
3
2451
by: InvisibleMan | last post by:
Thanks in Advance for any help on this - its truely sending my head in loops... so I appreciate your efforts! okay, I have a javascript listed below that drops down submenus contained within: <div class="small" style="display: none" id="menu1_menu"> when the heading is clicked: <a href=.. onClick="expandDiv('menu1')">
4
3231
by: johkar | last post by:
When the output method is set to xml, even though I have CDATA around my JavaScript, the operaters of && and < are converted to XML character entities which causes errors in my JavaScript. I know that I could externalize my JavaScript, but that will not be practical throughout this application. Is there any way to get around this issue? Xalan processor. Stripped down stylesheet below along with XHTML output. <?xml version='1.0'?>...
1
6432
by: ratnakarp | last post by:
Hi, I have a search text box. The user enters the value in the text box and click on enter button. In code behind on button click i'm writing the code to get the values from the database and binding it to a repeater control. This repeater control has multiple text boxes and buttons. Can you please tell me how can i do paging in this case ? I'm posting my code below. The problem is that if i click on "AdjustThisAd" button, it opens...
4
5629
by: drew197 | last post by:
I am a newbie. I am editing someone elses code to make it compatible with Firefox and Safari. In IE, when you click on the proper link, a block of text is shown in a nice paragraph form. But, in FireFox and Safari it appears as a narrow column of text with only 2-3 words per line. Here is the code: function showAll()
3
4496
by: Bob Sanderson | last post by:
I have a PHP web page which uses a HTML form. I would like to enter dates into the date fields using a JavaScript calendar, similar to the way phpMyAdmin does. Can anyone recommend a JavaScript that will do this? Also, how can I add a button to a form to enter a NULL. Thanks in advance.
0
7194
by: Tarik Monem | last post by:
I have been working on an all AJAX/DOM web site which is set to go live today and I thought I'd share my discoveries with all of you whom have helped me when I have encountered different issues along the way. First, deep linking is not something that a completely AJAX web site should be able to do by it's very nature of everything being on one page basically. So how can a person deep link to something that is on one page? This question...
22
2804
by: giordan | last post by:
Hi all! I've wrote this code: <script type="text/javascript"> var largImg; var altImg; var txtTop = '<b>Ottima scelta!</b> Ora compila il form e premi "Ricevi banner". Il codice HTML ti verrà mostrato in questa pagina e, per comodità, ti verrà inviato, via mail, all\'indirizzo da te fornito. Se invece vuoi cambiare il banner premi "Seleziona banner"'; var txtButton = 'Cambia banner'; var testo = '';
3
1495
by: pyro169 | last post by:
Hey I am making a tic tac toe game, im new to javascript, and when i make the game with 'buttons' and 'x' and 'o' it works perfectly, but i also made some pics and i can get the pics to show up, but i am unable to get the alerts to come up, and i cannot figure out how to make it so it wont allow you to click on the same block more then once. this is my complete code (with the gifs i am trying to use) .. any help at all would be appreaciated ...
0
9724
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
10127
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9201
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7665
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
6882
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
5552
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
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4336
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
2
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.