Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 759
  • Last Modified:

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

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
winbiz
Asked:
winbiz
  • 6
  • 6
1 Solution
 
maUruCommented:
Hi winbiz,


Cheers!
0
 
maUruCommented:
err, shouldnt you use

this.oInput.style.display = "";
0
 
maUruCommented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
callrsCommented:
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
 
callrsCommented:
P.S. There's two accepted answeres there. Try mine first...
0
 
winbizAuthor Commented:
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
 
callrsCommented:
: )

Welcome. But see my profile...

0
 
maUruCommented:
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
 
callrsCommented:
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
 
callrsCommented:
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
 
maUruCommented:
>> 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
 
callrsCommented:
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
 
maUruCommented:
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

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now