The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.

Javascript hellllllllp

redfenixredfenix Aka'd as rfixRegistered User regular
edited September 2008 in Help / Advice Forum
So I just started working on webpages again, but as a job this time.

Thing is, I'm competent with HTML and decent with JavaScript, but what i need to do is just slightly above my head.

the script I'm working with is here.

Instead of having the minutes selectable as-is, I need to have it only be :00, :15, :30, or :45.
where in the code do i do that?

Thanks for any help with this.

redfenix on

Posts

  • SporkAndrewSporkAndrew Registered User, ClubPA regular
    edited September 2008
    You need to have a play with the makeTimePart function. (This is a total hackjob, by the way. I'm sure you could make it better with some fiddling..)

    Change line 877 of calendar.js:
    var M = makeTimePart("minute", mins, 0, 45);
    

    Then in the middle of makeTimePart you need to change the for loop (lines 858 - 863) to:
    if (className == 'minute') {
                            for (var i = range_start; i <= range_end; i+15) {
                                  var txt;
                                  if (i == 0) txt = '0' + i;
                                  else txt = '' + i;
                                  part._range[part._range.length] = txt;
                             }
                        } else {
                             for (var i = range_start; i <= range_end; ++i) {
    			var txt;
    			if (i < 10 && range_end >= 10) txt = '0' + i;
    		            else txt = '' + i;
    		            part._range[part._range.length] = txt;
    		}
                        }
    

    That should make the selectable minutes an array that contains 00, 15, 30, 45. I haven't tested this out but I'm pretty sure that's what you need.

    Ps. Good choice on that calendar. I use it all over the place.

    SporkAndrew on
    The one about the fucking space hairdresser and the cowboy. He's got a tinfoil pal and a pedal bin
  • redfenixredfenix Aka'd as rfix Registered User regular
    edited September 2008
    I love you forever.

    Thanks for the input

    redfenix on
  • redfenixredfenix Aka'd as rfix Registered User regular
    edited September 2008
    would i overwrite
    if (typeof range_start != "number")
    					part._range = range_start;
    

    above it?

    redfenix on
  • SporkAndrewSporkAndrew Registered User, ClubPA regular
    edited September 2008
    Naw, you need to leave that there.

    SporkAndrew on
    The one about the fucking space hairdresser and the cowboy. He's got a tinfoil pal and a pedal bin
  • redfenixredfenix Aka'd as rfix Registered User regular
    edited September 2008
    alright, i'm getting this error:

    scriptprob.png

    which is this line:
    part._range[part._range.length] = txt;
    

    redfenix on
  • SporkAndrewSporkAndrew Registered User, ClubPA regular
    edited September 2008
    Oops, hah, yeah. That'll never do anything other than stay at 0.

    Replace:
    for (var i = range_start; i <= range_end; i+15) {
    

    with
    for (var i = range_start; i <= range_end; i+=15) {
    

    SporkAndrew on
    The one about the fucking space hairdresser and the cowboy. He's got a tinfoil pal and a pedal bin
  • redfenixredfenix Aka'd as rfix Registered User regular
    edited September 2008
    It's getting there.
    now that spawns the calendar at the bottom of the page, and gives the options: 00, 15, 30, undefined.

    Sorry this is such a pain in the ass

    redfenix on
  • SporkAndrewSporkAndrew Registered User, ClubPA regular
    edited September 2008
    You mean you don't want people to be able to pick undefined? Picky picky picky..

    I'm gonna have a play and actually test it out myself. Something I probably should've done from the start. At least it looks like work anyway.

    SporkAndrew on
    The one about the fucking space hairdresser and the cowboy. He's got a tinfoil pal and a pedal bin
  • redfenixredfenix Aka'd as rfix Registered User regular
    edited September 2008
    You mean you don't want people to be able to pick undefined? Picky picky picky..

    I'm gonna have a play and actually test it out myself. Something I probably should've done from the start. At least it looks like work anyway.

    for the hell of it, i emailed you the .htm i was working on to your profile email

    redfenix on
  • SporkAndrewSporkAndrew Registered User, ClubPA regular
    edited September 2008
    Ok, I tried that but instead of changing the first line like I said:
    var M = makeTimePart("minute", mins, 0, 45);
    

    I left it as it was (0,59 I think) and then it cycled through the times correctly. Well, first it showed the current time and then clicking it changed it to 0, 15, 30, 45 and back to 0..

    Can you try setting it back to
    var M = makeTimePart("minute", mins, 0, 59);
    

    and seeing what happens?

    SporkAndrew on
    The one about the fucking space hairdresser and the cowboy. He's got a tinfoil pal and a pedal bin
  • redfenixredfenix Aka'd as rfix Registered User regular
    edited September 2008
    00,15,30, undefined

    redfenix on
  • SporkAndrewSporkAndrew Registered User, ClubPA regular
    edited September 2008
    Ok, sorry I'm fresh out of ideas then. For some reason it's not appearing as "undefined" here but going to 45 and then looping around again.. Are you using the calendar-setup.js file?

    The only suggestion I can make is take out the calendar code and start afresh. Try getting it to work on a page that just contains the date field and nothing else and then if that works think about getting it back into that page.

    SporkAndrew on
    The one about the fucking space hairdresser and the cowboy. He's got a tinfoil pal and a pedal bin
Sign In or Register to comment.