Solved

Why does Javascript display property "block" not always hide my object?

Posted on 2006-06-26
13
749 Views
Last Modified: 2010-04-06
Hi everyone,

1) I'm using the following method to cause an ojbect on my form to either be hidden or displayed.

//  this.oInput.style.display = "none";
//  this.oInput.style.display = "block";

2) However the block property does not always cause the object to be hidden. Particularly when my form is first loaded!. It's incredibily frustrating!!

3) Can someone tell me what difference between the "block" and  : style.visibility = 'hidden' methods is. And if there are any other javascript methods to hide and control an object is.

I'd really appreciate some enlightenment on on this one.

Thanks in advance everyone.

Regards,

winbiz
0
Comment
Question by:winbiz
  • 6
  • 6
13 Comments
 
LVL 7

Expert Comment

by:maUru
ID: 16987586
Hi winbiz,


Cheers!
0
 
LVL 7

Expert Comment

by:maUru
ID: 16987593
err, shouldnt you use

this.oInput.style.display = "";
0
 
LVL 7

Expert Comment

by:maUru
ID: 16987626
2) However the block property does not always cause the object to be hidden. Particularly when my form is first loaded!. It's incredibily frustrating!!
block doesnt 'hide' it tells css how to display it (block or inline)

3) Can someone tell me what difference between the "block" and  : style.visibility = 'hidden' methods is. And if there are any other javascript methods to hide and control an object is.

usually for hiding in javascript you do:

//  this.oInput.style.display = "none";

and to show its:
//  this.oInput.style.display = "";
0
 
LVL 30

Accepted Solution

by:
callrs earned 500 total points
ID: 16987799
Run the example I've made at http:Q_21896971.html
(Select, Copy, Paste to notepad, save as c:\temp\hideshow.htm, type c:\temp\hideshow.htm in address bar in browser)


: )
0
 
LVL 30

Expert Comment

by:callrs
ID: 16987826
P.S. There's two accepted answeres there. Try mine first...
0
 

Author Comment

by:winbiz
ID: 16988116
Callrs!!!

Thank you very, very, very much!

Learning in an informal manner as I am/have can make it difficult to recognize that more than one method for accomplishing is available, let alone the implications each method has.

You little script did both succinctly and clearly.

Regards,

wb
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 30

Expert Comment

by:callrs
ID: 16988167
: )

Welcome. But see my profile...

0
 
LVL 7

Expert Comment

by:maUru
ID: 16988217
winbiz,

dont ask a question but then accept an answer which does not actually answer the actual question

so in the future, ask: how can i make a switch on, switch off toggle for 2 divs using javascript

which i could have easily posted as my first response but it wasnt what you asked for.

that way you do not waste my time.
0
 
LVL 30

Expert Comment

by:callrs
ID: 16988699
Asker has asked "Can someone tell me what difference between the "block" and  : style.visibility = 'hidden' methods is. And if there are any other javascript methods to hide and control an object"

Just as a picture is worth a thousand words, a working example, with simplified neatly ordered code, helps more than any explanation. In fact it  IS the explanation as the mind can see instantly "what the difference" is. Even the link that I provide in the example agrees: "This is a test page to CLARIFY the difference..." (emphasis added).

Asker asked "I'd really appreciate some enlightenment on on this one"
And she got it.

Would you rather sit through a lecture on, for example, the difference between a  "ThingAMaJig" and a "RingAMaThig", or have it shown to you, so that it's SELF-EXPLANATORY?

A demo that  explains itself saves us a lot of time when we can see the difference instantly...

Cheers.

- R.S.
0
 
LVL 30

Expert Comment

by:callrs
ID: 16988732
And as a bonus, asker now has a full working template to quickly deploy in own code. So the end purpose in asking-- to be able to code with understanding -- is better fulfilled.
0
 
LVL 7

Expert Comment

by:maUru
ID: 16988838
>> I'd really appreciate some enlightenment on on this one.

he is asking /why/ not /how/

>> However the block property does not always cause the object to be hidden. Particularly when my form is first loaded!. It's incredibily frustrating!!
>> A demo that  explains itself saves us a lot of time when we can see the difference instantly...

i mean, if you were to ask winbiz right now why did your code do what he said in point 2), he would not know what to say

callrs, my problem is not the answer given, it was that winbiz is not a coder, and therefore will take the code, use it and not realise/care why or why not his code didnt work, and thats all good.

but he asked the /wrong/ question for the answer he was looking for, thereby wasting my time and im want to point it out to him (not about wasting my time, but so in the future he can ask questions that are specific to what he is looking for so experts who spend their free time on this site dont get annoyed).

say the thing was reversed, he asked 'how can i write a showhide function' and you spend 20 minutes writing a whole function out, only for him to say, no no i dont want code i want to know ' what difference between the "block" and  : style.visibility = 'hidden' methods is'

ah fuck it im tired.
0
 
LVL 30

Expert Comment

by:callrs
ID: 16988977
It takes longer time to write well, to be specific, etc., especially when faced with non-working code. It's up to 'experts' to direct, to help in the best & quickest way possible. Asker had a need, expressed it, and accepted the answer that best met that need.

But anyway, we can debate the point all night, not what I want to do.

I feel you do deserve some points, which you can get by saying a word or two here: http://www.experts-exchange.com/Web/Web_Languages/Q_21899994.html

: )
0
 
LVL 7

Expert Comment

by:maUru
ID: 16988992
heh callrs, thanks but i dont care about the points, i just want winbiz (and others) to be more specific in the future, because it helps everyone.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now