Solved

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

Posted on 2006-06-26
13
746 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

757 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

21 Experts available now in Live!

Get 1:1 Help Now