Page 2 of 6 FirstFirst 1234 ... LastLast
Results 11 to 20 of 60

Thread: JavaScript Validation?

  1. #11
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Actually, I made Penguin Popcorn Parade and Petentine's Day up.
    Ahahaha, I should've guessed
    I noticed var holiday = holidays[(month + 1) + "/" + day] || [humanMonth + " " + day, ""];. Yikes!
    I'm guessing that means that holiday's value is humanMonth and day's value unless month + 1 and day have the same value of an object in the holidays array. In that case, holiday's value equals the first value in the correct object and then the second value in the CSS class exclamation.
    Yes. To break it down:
    • Concatenate the month (plus one), a slash, and the date, so it's in the form '3/1'
    • Get a value from holidays using that as the key
    • If that value doesn't exist, or is false, empty, 0, or null, use the array [humanMonth + " " + day, ""] instead
    • Assign the result to holiday.
    In Javascript, an or operation returns the first true value it encounters. So:
    Code:
    var a = false, b = 0, c = "Truthy string";
    var d = a || b || c; // d is "Truthy string"
    var e = a || null || c || b; // e is "Truthy string"
    var f = b || true || c; // f is true
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  2. #12
    Join Date
    Feb 2007
    Location
    🌎
    Posts
    528
    Thanks
    10
    Thanked 10 Times in 10 Posts
    Blog Entries
    2

    Default

    By the way, what does イギリス mean and in what language?

  3. #13
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    England, in Japanese.

    (Why can't you write it in ENGLISH, Twey? )
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  4. #14
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Because that would be boring

    The other way the Japanese have of writing England is 英国, which, purely through phonetics, literally means "hero land." I pity Germans in Japan: they get to be 独逸人, "lonely lazy people" (独逸 is pronounced "doitsu" which is about as close to the German pronunciation of "Deutsch" as the Japanese syllabaries can get).
    Last edited by Twey; 03-02-2007 at 02:58 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #15
    Join Date
    Feb 2007
    Location
    🌎
    Posts
    528
    Thanks
    10
    Thanked 10 Times in 10 Posts
    Blog Entries
    2

    Default

    I see you changed it to 英国.

  6. #16
    Join Date
    Feb 2007
    Location
    🌎
    Posts
    528
    Thanks
    10
    Thanked 10 Times in 10 Posts
    Blog Entries
    2

    Default

    Why is EVERYTHING choking on
    HTML Code:
    <marquee behavior="normal" direction="left">Welcome
    to SGB Airport. Next shuttle
    leaves 
          <script type="text/javascript">
    var date = new Date();
    var key = date.getMinutes();
    var leaves;
    var now = "no";
    
    switch (key) {
    case 0 :
    leaves = "in 0 minutes";
    now = "yes";
    break;
    case 1 :
    leaves = "in 4 minutes";
    break;
    case 2 :
    leaves = "in 3 minutes"
    break;
    case 3 :
    leaves = "in 2 minutes"
    break;
    case 4 :
    leaves = "in 1 minute"
    break;
    case 5 :
    leaves = "in 0 minutes";
    now = "yes";
    break;
    case 6 :
    leaves = "in 4 minutes";
    break;
    case 7 :
    leaves = "in 3 minutes"
    break;
    case 8 :
    leaves = "in 2 minutes"
    break;
    case 9 :
    leaves = "in 1 minute"
    break;
    case 10 :
    leaves = "in 0 minutes";
    now = "yes";
    break;
    case 11 :
    leaves = "in 4 minutes";
    break;
    case 12 :
    leaves = "in 3 minutes"
    break;
    case 13 :
    leaves = "in 2 minutes"
    break;
    case 14 :
    leaves = "in 1 minute"
    break;
    case 15 :
    leaves = "in 0 minutes";
    now = "yes";
    break;
    case 16 :
    leaves = "in 4 minutes";
    break;
    case 17 :
    leaves = "in 3 minutes"
    break;
    case 18 :
    leaves = "in 2 minutes"
    break;
    case 19 :
    leaves = "in 1 minute"
    break;
    case 20 :
    leaves = "in 0 minutes";
    now = "yes";
    break;
    case 21 :
    leaves = "in 4 minutes";
    break;
    case 22 :
    leaves = "in 3 minutes"
    break;
    case 23 :
    leaves = "in 2 minutes"
    break;
    case 24 :
    leaves = "in 1 minute"
    break;
    case 25 :
    leaves = "in 0 minutes";
    now = "yes";
    break;
    case 26 :
    leaves = "in 4 minutes";
    break;
    case 27 :
    leaves = "in 3 minutes"
    break;
    case 28 :
    leaves = "in 2 minutes"
    break;
    case 29 :
    leaves = "in 1 minute"
    break;
    case 30 :
    leaves = "in 0 minutes";
    now = "yes";
    break;
    case 31 :
    leaves = "in 4 minutes";
    break;
    case 32 :
    leaves = "in 3 minutes"
    break;
    case 33 :
    leaves = "in 2 minutes"
    break;
    case 34 :
    leaves = "in 1 minute"
    break;
    case 35 :
    leaves = "in 0 minutes";
    now = "yes";
    break;
    case 36 :
    leaves = "in 4 minutes";
    break;
    case 37 :
    leaves = "in 3 minutes"
    break;
    case 38 :
    leaves = "in 2 minutes"
    break;
    case 39 :
    leaves = "in 1 minute"
    break;
    case 40 :
    leaves = "in 0 minutes";
    now = "yes";
    break;
    case 41 :
    leaves = "in 4 minutes";
    break;
    case 42 :
    leaves = "in 3 minutes"
    break;
    case 43 :
    leaves = "in 2 minutes"
    break;
    case 44 :
    leaves = "in 1 minute"
    break;
    case 45 :
    leaves = "in 0 minutes";
    now = "yes";
    break;
    case 46 :
    leaves = "in 4 minutes";
    break;
    case 47 :
    leaves = "in 3 minutes"
    break;
    case 48 :
    leaves = "in 2 minutes"
    break;
    case 49 :
    leaves = "in 1 minute"
    break;
    case 50 :
    leaves = "in 0 minutes";
    now = "yes";
    break;
    case 51 :
    leaves = "in 4 minutes";
    break;
    case 52 :
    leaves = "in 3 minutes"
    break;
    case 53 :
    leaves = "in 2 minutes"
    break;
    case 54 :
    leaves = "in 1 minute"
    break;
    case 55 :
    leaves = "in 0 minutes";
    now = "yes";
    break;
    case 56 :
    leaves = "in 4 minutes";
    break;
    case 57 :
    leaves = "in 3 minutes"
    break;
    case 58 :
    leaves = "in 2 minutes"
    break;
    case 59 :
    leaves = "in 1 minute"
    break;
    }
    if (now == "yes") {
    window.location="shuttle.html"
    }
    else {
    window.location="index.html"
    }
    document.write(leaves);
          </script>.</marquee>

  7. #17
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    <marquee behavior="normal" direction="left">
    <marquee> is a big no-no in web design
    var now = "no";
    Use a boolean value, or even just check whether leaves is 0.
    switch (key) {
    Dear gods! You're raping switch!
    document.write(leaves);
    This will never be reached -- the browser will be directed to either shuttle.html or index.html, but either way it happens before this.

    Factor in all of the above, and you can write that hideously huge switch statement in two lines:
    Code:
    var leaves = (function(x) { var v = x &#37; 5; return (v === 0 ? 0 : 5) - v; })((new Date()).getMinutes());
    
    window.location.href = (leaves === 0 ? "shuttle.html" : "index.html");
    If you want to write that time rather than redirect to index.html, you can:
    Code:
    var leaves = (function(x) { var v = x % 5; return (v === 0 ? 0 : 5) - v; })((new Date()).getMinutes());
    
    if(leaves === 0)
      window.location.href = "shuttle.html";
    else
      document.write("in " + leaves + " minute" + (leaves === 1 ? "" : "s"));
    Last edited by Twey; 03-04-2007 at 06:18 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #18
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Lol... raping? Not raping, but definitely over-using. In fact, I never use switch. Arrays are much easier to use.
    - Mike

  9. #19
    Join Date
    Feb 2007
    Location
    🌎
    Posts
    528
    Thanks
    10
    Thanked 10 Times in 10 Posts
    Blog Entries
    2

    Default

    Huh?

    var leaves = (function(x) { var v = x &#37; 5; return (v === 0 ? 0 : 5) - v; })((new Date()).getMinutes());

    window.location.href = (leaves === 0 ? "shuttle.html" : "index.html");?

    Is there any way to make that update every minute...or does it already? And what was the actual problem with the first one?

  10. #20
    Join Date
    Feb 2007
    Location
    🌎
    Posts
    528
    Thanks
    10
    Thanked 10 Times in 10 Posts
    Blog Entries
    2

    Default

    I never learned what an array was, all I learned was if...else and switch.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •