Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-04-2013, 09:15 PM   PM User | #16
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Quote: "a journey of a thousand miles begins with a single step"
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 01-04-2013, 09:21 PM   PM User | #17
MrTIMarshall
Regular Coder

 
Join Date: Nov 2010
Posts: 347
Thanks: 44
Thanked 1 Time in 1 Post
MrTIMarshall is an unknown quantity at this point
Quote:
Originally Posted by AndrewGSW View Post
Quote: "a journey of a thousand miles begins with a single step"
I don't even know the first step, lols.

I understand that this:
Code:
var ckbs = document.getElementsByTagName('input');
for (var i=0; i < ckbs.length; i++) {
    if (ckbs[i].type == 'checkbox') {
        // do something 
    }
}
is calling to all checkboxes on the page, however I need to change the, lets sayfor example if Obj2012-Check is checked then Obj2012 class needs to change but if Obj2011-Check is checked then Obj2011 call needs to change
MrTIMarshall is offline   Reply With Quote
Old 01-04-2013, 10:04 PM   PM User | #18
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Code:
var ckbs = document.getElementsByTagName('input');
for (var i=0; i < ckbs.length; i++) {
    if (ckbs[i].type == 'checkbox') {
        if ((ckbs[i].id).indexOf('Obj') + 1) {
            // that is, if the id includes 'Obj' 
            // you'll need other string functions if you have to check 
            // other parts of the id
            if (ckbs[i].checked) {
                ckbs[i].className = "wibble";
            } // else: see a previous post of mine
        }
    }
}
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS

Last edited by AndrewGSW; 01-04-2013 at 10:07 PM..
AndrewGSW is offline   Reply With Quote
Old 01-04-2013, 10:09 PM   PM User | #19
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Or use

Code:
if ((ckbs[i].id).indexOf('Obj') == 0) {
if the id will start with 'Obj'.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 01-04-2013, 10:38 PM   PM User | #20
MrTIMarshall
Regular Coder

 
Join Date: Nov 2010
Posts: 347
Thanks: 44
Thanked 1 Time in 1 Post
MrTIMarshall is an unknown quantity at this point
I implemented this into my page, howver it does not work and yes I did change the class name to the correct class 'Done'.
MrTIMarshall is offline   Reply With Quote
Old 01-04-2013, 11:08 PM   PM User | #21
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,236
Thanks: 59
Thanked 3,997 Times in 3,966 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
What's the new URL?

Let's just throw out your old code and do it again, maybe?
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 01-04-2013, 11:10 PM   PM User | #22
MrTIMarshall
Regular Coder

 
Join Date: Nov 2010
Posts: 347
Thanks: 44
Thanked 1 Time in 1 Post
MrTIMarshall is an unknown quantity at this point
https://tornhq.com/Events/HallowTown...ml#view_quests
MrTIMarshall is offline   Reply With Quote
Old 01-04-2013, 11:19 PM   PM User | #23
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,236
Thanks: 59
Thanked 3,997 Times in 3,966 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Okay, the problem is that you are *NOT* dealing with an ordinary checkbox.

Since you are using that checkbox.js code, *it* is taking over the onclick method of your checkboxes! So anything you try to add to *also* handle the onclick's is going to either (a) interfere with the checkbox.js code or (b) OVERWRITE the checkbox.js code or (c) get itself overwritten by the checkbox.js code.

The most practical things to do to fix this are either (a) stop using checkbox.js and write your own equivalent code or (b) modify checkbox.js to also change the class upon the onclick.

Which do you choose?
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 01-04-2013, 11:43 PM   PM User | #24
MrTIMarshall
Regular Coder

 
Join Date: Nov 2010
Posts: 347
Thanks: 44
Thanked 1 Time in 1 Post
MrTIMarshall is an unknown quantity at this point
To be honest, I do not even know how the checkbox.js works so I won't be able to program my own, well, at this moment in time anyway.

There are also quite a lot of these to implement. I'll go for your best option though as you have helped so much and are more experienced in the field.
MrTIMarshall is offline   Reply With Quote
Old 01-04-2013, 11:44 PM   PM User | #25
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,236
Thanks: 59
Thanked 3,997 Times in 3,966 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Personally, I feel that checkbox.js code is needlessly overcomplicated. I'd prefer to rip it out and write my own.

Do you *care* that a person without JavaScript would then see ordinary checkboxes, as with checkbox.js? Of course not. Your page won't even BEGIN to run without JS.

So let me toss out checkbox.js and make it tons simpler.

Why do you want class to change because of checked, by the by?
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 01-04-2013, 11:45 PM   PM User | #26
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,236
Thanks: 59
Thanked 3,997 Times in 3,966 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Quote:
Originally Posted by MrTIMarshall View Post
There are also quite a lot of these to implement.
A lot of what? checkboxes?
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 01-04-2013, 11:49 PM   PM User | #27
MrTIMarshall
Regular Coder

 
Join Date: Nov 2010
Posts: 347
Thanks: 44
Thanked 1 Time in 1 Post
MrTIMarshall is an unknown quantity at this point
Yes, there are 3 sub-categories with a total of 60 things to do for the 2012 objectives and I've not yet found reliable sources for the other years.
MrTIMarshall is offline   Reply With Quote
Old 01-04-2013, 11:54 PM   PM User | #28
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,236
Thanks: 59
Thanked 3,997 Times in 3,966 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Okay...but now answer me: What is the reason you want to change the class of the checkbox when it is checked??
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 01-05-2013, 12:01 AM   PM User | #29
MrTIMarshall
Regular Coder

 
Join Date: Nov 2010
Posts: 347
Thanks: 44
Thanked 1 Time in 1 Post
MrTIMarshall is an unknown quantity at this point
To symbolize that they have done them.
  • Red means uncompleted
  • Orange means they've started.
  • Green means they've completed

This will lead on to showing the markers on the map. If they've not checked that they have completed 2011 for example or not checked everything in-side to auto-check the 2011 objectives, the 2012 objectives will not show on the map as they don't be available.

I'm hoping once I know a basic of both, the showing of images on the map and these checkboxes I can get started on doing loads myself. There are some big array's for myself to complete and quite a lot of research to try and find the previous years objectives although these do not get removed and you do a continuation, these should be easy to find but aren't as the help websites out there are rubbish, hence why I am working on this and meant to be working on other things.
MrTIMarshall is offline   Reply With Quote
Old 01-05-2013, 12:02 AM   PM User | #30
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
I know that OldPedant is on the case , but if it is useful to you below is what I have used for a check/tick box and I've attached small images.

Code:
<!DOCTYPE html>
<html lang="en-GB">
<head>
    <meta charset="utf-8">
    <meta name="keywords" content="key, words">
    <meta name="description" content="description">
    <title>Check It</title>
    <style type="text/css">
    label {
        display: block;
        margin-top: 2px; margin-bottom: 2px;
    }

    label.checking input[type=checkbox] {
        display: inline;
        width: 1.2em;
        vertical-align: middle;
        outline: none;
        opacity: 0;
        width: 18px; height: 18px;
        margin: 0 0 0 8px; padding: 0;
        z-index: 10;
    }
    span.checking {
        margin: 0;
        padding: 0 0 0 18px;
        position: relative; left: -18px;
        z-index: 5;
        height: 18px;
        background: url('images/checkblank.png') right center no-repeat;
    }
    label.checking input[type=checkbox]:checked + span {
        background: url('images/checktick.png') right center no-repeat;
    }

    </style>
</head>
<body>
<label class="checking">Remember me<input type="checkbox" id="remember" 
        name="remember" value="yes"><span class="checking"></span></label>
</body>
</html>
OPs work though is likely to be more specific to you.
Attached Files
File Type: zip checkimages.zip (19.0 KB, 4 views)
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 03:54 AM.


Advertisement
Log in to turn off these ads.