469,647 Members | 1,778 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,647 developers. It's quick & easy.

if getElementById && getElementById?

chunk1978
224 100+
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.getElementById('DIVinvoicesubtotal').sty le.display='block'=True

thanks in advance
Feb 9 '07 #1
7 8296
dmjpro
2,476 2GB
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 100+
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.display='none'"...

the mystery continues...
Feb 9 '07 #3
dorinbogdan
839 Expert 512MB
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 Expert 512MB
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 100+
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 Expert Mod 8TB
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 Expert Mod 8TB
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

Post your reply

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

Similar topics

2 posts views Thread by Adam | last post: by
1 post views Thread by ratnakarp | last post: by
4 posts views Thread by drew197 | last post: by
3 posts views Thread by Bob Sanderson | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.