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
Javascript IF problem.
Old 03-03-2010, 03:34 PM Javascript IF problem.
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Hi Guys,

Im USELESS! with javascript. Can someone help here?

Ive got the below,
This works fine:
var objDiv = document.getElementById("publictext");
objDiv.scrollTop = objDiv.scrollHeight;
var objDiv = document.getElementById("privatetext");
objDiv.scrollTop = objDiv.scrollHeight;

I want to check if a checkbox id=chk is checked.
If it is, Do the above 4 lines.

If it isnt.
Do nothing.

How can i get this to work?

Thanks
G

Code:
function scroller(){
    
    var scrolling = document.getElementById('chk');
    if(scrolling.checked != "checked")
    else
    var objDiv = document.getElementById("publictext");
    objDiv.scrollTop = objDiv.scrollHeight;
    var objDiv = document.getElementById("privatetext");
    objDiv.scrollTop = objDiv.scrollHeight;
    
  

}
__________________

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


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
 
Register now for full access!
Old 03-03-2010, 03:48 PM Re: Javascript IF problem.
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
In JavaScript the checked property is a simple boolean, so

Code:
if(scrolling.checked) {

}
will suffice

Also, your if statement is not structured correctly. Wrap everything in {} to avoid confusion. Placing the 'else' on a line immediately after the 'if' is not doing what you think.
__________________
I build web things. I work for the startup
Please login or register to view this content. Registration is FREE
.

Last edited by wayfarer07; 03-03-2010 at 03:50 PM..
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 03-03-2010, 03:59 PM Re: Javascript IF problem.
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Ty, Thats great.

Works like a charm. Something so simple, but i have a terrible problem understanding how JS actually talks to the elements in the document.

I try to stick to PHP but need some JS form time to time

Ty again
__________________

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


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Reply     « Reply to Javascript IF problem.
 

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.12725 seconds with 12 queries