Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Old 03-24-2008, 07:51 PM Changing visibility
pealo86's Avatar
Super Spam Talker

Posts: 850
Name: Matt Pealing
Location: England, north west
Trades: 0
Im trying to create a simple script that will make a <p> tag appear, but in the Firefox console I get the error

Quote:
document.form1.visible has no properties
here is the code im using:

CSS:
Code:
.visible {
visibility:hidden;}
HTML:
Code:
<p class="visible" id="visible">
        <label for="other" class="labelDef">Other</label>
        <input type="text" name="other" id="other" />
        <label for="button"></label>
        <br class="clear" />
      </p>
JavaScript:
Code:
function appear()
    {
        document.form1.visible.style.visibility="visible";
    }
Any ideas what Im doing wrong? I did originally set it so that the html name could be passed as an argument, as I wanted to be able to re use the script for other elements. But the script was causing me so much hassle its wound its way down to what's above!
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
 
Register now for full access!
Old 03-24-2008, 08:16 PM Re: Changing visibility
vangogh's Avatar
Post Impressionist

Posts: 10,688
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
First you don't need both the class and the id. In general it's one or the other. In this case I'd suggest using the id.

Try this for the funtion

HTML Code:
function appear(){
  var vis = document.getElementByID("visible");
  vis.style.visibility = "visible"
}
I don't see where in your code you're calling the function, but I'll assume you're doing that somewhere else not shown here. If not you do need to call the function at some point.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 03-24-2008, 08:32 PM Re: Changing visibility
pealo86's Avatar
Super Spam Talker

Posts: 850
Name: Matt Pealing
Location: England, north west
Trades: 0
Thanks its working now! I was sure I had something similiar to that originially aswell!
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
Old 03-24-2008, 08:39 PM Re: Changing visibility
pealo86's Avatar
Super Spam Talker

Posts: 850
Name: Matt Pealing
Location: England, north west
Trades: 0
Hmmm Ive now tried altering the code to this:

HTML:
Code:
onClick="appear(visible)"
JS:
Code:
function appear(element)
    {
        vis = document.getElementById(element);
        vis.style.visibility = "visible";
    }
But now it wont work??
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
Old 03-24-2008, 09:36 PM Re: Changing visibility
vangogh's Avatar
Post Impressionist

Posts: 10,688
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
I think you might need to wrap quotes around 'visible' when you pass it to the function in the onClick. Not 100% sure, but try

onclick="appear('visible')"
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 03-25-2008, 05:12 AM Re: Changing visibility
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
that's correct, without quotes "visible" would be taken as a variable name and the value of that will be passed to the function.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-25-2008, 10:50 AM Re: Changing visibility
pealo86's Avatar
Super Spam Talker

Posts: 850
Name: Matt Pealing
Location: England, north west
Trades: 0
Thanks, I used apostrophe's and it worked. Whats really annoying me is that I tried that last night and it still wouldnt work! I tried deleting my browser history to make sure that the page would refresh properly and it still made no difference!

I know it sounds like Im making it up, but Im not lol.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
Old 03-25-2008, 08:05 PM Re: Changing visibility
vangogh's Avatar
Post Impressionist

Posts: 10,688
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
I don't think you're making it up. Odd things like that have happened to me too. You'd swear you tried something one way and it didn't work and later it does work.

I think it's usually us thinking we tried something when we really missed one part of it. Either that or it's gremlins.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Reply     « Reply to Changing visibility
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.63414 seconds with 12 queries