Page 1 of 6 123 ... LastLast
Results 1 to 10 of 60

Thread: JavaScript Validation?

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

    Question JavaScript Validation?

    Does anyone know of a free online place to validate your JavaScripts? I am just starting to write long JavaScripts, and most of them don't work I test mine in FX 2, IE 7 and NS 8. I write my scripts in Notepad++. The least basic script I got to work was:

    Code:
    var date = new Date();
    var month = date.getMonth();
    var showmonth;
    var day = date.getDate();
    
    switch (month) {
    case 0:
    showmonth = "January";
    break;
    ...
    default: showmonth = "INVALID";
    }
    
    document.write(showmonth + " " + date);
    or something like that.
    Basically, I'm looking for a place where you send in your JavaScript and an actual person looks at the code and fixes it so that it works.

    Any help would be greatly appreciated!
    Last edited by techno_race; 02-28-2007 at 01:18 AM.

  2. #2
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    get firebug addon for FF.

    It has a js error console.
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

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

    Default

    I seriously need an actual person to do it because the person would know what I meant by something!

  4. #4
    Join Date
    Feb 2007
    Location
    North Vancouver, BC, CANADA
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Why not just ask someone in the forum, I sure maybe someone wouldn't mind helping....if it isn't to long

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

    Default

    In that case, does anybody know why this doesn't work?
    Code:
    //Fruit and vegetable of the month
    
    var computer = new Date();
    var month = computer.getMonth;
    var fruit;
    var fv;
    
    switch (month) {
    	case 0:
    		fruit = 'oranges';
    		fv = 'Fruit';
    		break;
    	case 1:
    		fruit = 'oranges';
    		fv = 'Fruit';
    		break;
    	case 2:
    		fruit = 'lettuce';
    		fv = 'Vegetable';
    		break;
    	case 3:
    		fruit = 'lettuce';
    		fv = 'Vegetable';
    		break;
    	case 4:
    		fruit = 'lettuce';
    		fv = 'Vegetable';
    		break;
    	case 5:
    		fruit = 'lettuce';
    		fv = 'Vegetable';
    		break;
    	case 6:
    		fruit = 'tomatoes';
    		fv = 'Fruit';
    		break;
    	case 7:
    		fruit = 'tomatoes';
    		fv = 'Fruit';
    		break;
    	case 8:
    		fruit = 'tomatoes';
    		fv = 'Fruit';
    		break;
    	case 9:
    		fruit = 'tomatoes';
    		fv = 'Fruit';
    		break;
    	case 10:
    		fruit = 'oranges';
    		fv = 'Fruit';
    		break;
    	case 11:
    		fruit = 'oranges';
    		fv = 'Fruit';
    		break;
    }
    
    document.write('The ' + fv + ' of the Month is ' + fruit + '.');
    It shows up in all the browsers as nothing.
    Any modifications are greatly appreciated!

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

    Default

    If you find yourself doing a numerical switch like that, you may as well use an array. The error, though, is caused by this:
    Code:
    var month = computer.getMonth;
    You don't want the function getMonth, you want its return value, so you should say getMonth().
    Code:
    //Fruit and vegetable of the month
    var product = [
      ["oranges", "Fruit"],
      ["oranges", "Fruit"],
      ["lettuce", "Vegetable"],
      ["lettuce", "Vegetable"],
      ["lettuce", "Vegetable"],
      ["lettuce", "Vegetable"],
      ["tomatoes", "Fruit"],
      ["tomatoes", "Fruit"],
      ["tomatoes", "Fruit"],
      ["tomatoes", "Fruit"],
      ["oranges", "Fruit"],
      ["oranges", "Fruit"]
    ][(new Date()).getMonth()];
    
    document.write('The ' + product[1] + ' of the Month is ' + product[0] + '.');
    There are various other ways this could be improved too, but not without taking it beyond beginner level.
    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!

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

    Red face JANUARY1 is not defined!?

    I SERIOUSLY need help with this one. All I can get out of my computer is 'JANUARY1 is not defined.' Meaning?
    Code:
    var finddate = new Date();
    var findmonth = finddate.getMonth();
    var findday = finddate.getDate();
    var holiday;
    var exclaim;
    var displayMonth;
    var findyear = finddate.getYear();
    
    switch (findmonth) {
    	case 0 :
    		displayMonth = "JANUARY"
    		break
    	case 1 :
    		displayMonth = "FEBRUARY"
    		break
    	case 2 :
    		displayMonth = "MARCH"
    		break
    	case 3 :
    		displayMonth = "APRIL"
    		break
    	case 4 :
    		displayMonth = "MAY"
    		break
    	case 5 :
    		displayMonth = "JUNE"
    		break
    	case 6 :
    		displayMonth = "JULY"
    		break
    	case 7 :
    		displayMonth = "AUGUST"
    		break
    	case 8 :
    		displayMonth = "SEPTEMBER"
    		break
    	case 9 :
    		displayMonth = "OCTOBER"
    		break
    	case 10 :
    		displayMonth = "NOVEMBER"
    		break
    	case 11 :
    		displayMonth = "DECEMBER"
    		break
    	
    	default: displayMonth = "INVALID"
    }
    
    var findholiday = displayMonth + findday
    
    switch (findholiday) {
    	case JANUARY1 :
    		holiday = "New Year's Day"
    		exclaim = "Happy " + findyear
    		break
    	case JANUARY15 :
    		holiday = "Martin Luther King, Jr.'s Birthday"
    		exclaim = "Feel the freedom"
    		break
    	case JANUARY27 :
    		holiday = "the Penguin Popcorn Parade"
    		exclaim = "Munch, munch, munch"
    		break
    	case FEBRUARY2 :
    		holiday = "Groundhog's Day"
    		exclaim = "Let's hope he'll wake up"
    		break
    	case FEBRUARY12 :
    		holiday = "Abraham Lincoln's Birthday"
    		exclaim = "Goodbye, slavery"
    		break
    	case FEBRUARY14 :
    		holiday = "Valentine's Day"
    		exclaim = "Feel the love"
    		break
    	case FEBRUARY15 :
    		holiday = "Petentine's Day"
    		exclaim = "Slurp, slurp, slurp"
    		break
    	case FEBRUARY22 :
    		holiday = "George Washington's Birthday"
    		exclaim = "Fly the flag"
    		break
    	case MARCH17 :
    		holiday = "St. Patrick's Day"
    		exclaim = "It's hard to find <i>any</i> clovers"
    		break
    	case APRIL1 :
    		holiday = "April Fool's Day"
    		exclaim = "My computer is laughing"
    		break
    	case APRIL10 :
    		holiday = "ASPCA's Birthday"
    		exclaim = "Woof, woof, woof"
    		break
    	case APRIL22 :
    		holiday = "Earth Day"
    		exclaim = "I think I use too many watts"
    		break
    	case JUNE14 :
    		holiday = "Flag Day"
    		exclaim = "Someone design an Antarctica flag"
    		break
    	case JULY4 :
    		holiday = "Independence Day"
    		exclaim = "Fireworks scare me"
    		break
    	case AUGUST29 :
    		holiday = "Henry Bergh's Birthday"
    		exclaim = "1813? Yikes"
    		break
    	case OCTOBER31 :
    		holiday = "Halloween"
    		exclaim = "Whooooooo"
    		break
    	case DECEMBER25 :
    		holiday = "Christmas"
    		exclaim = "Smell the gingerbread"
    		break
    	case DECEMBER31 :
    		holiday = "New Year's Eve"
    		exclaim = "Goodbye, " + findyear
    		break
    	
    	default: holiday = displayMonth + " " + findday; exclaim = ""
    }
    
    document.write("It's " + holiday + "!<br><center><font class=exclamation>" + exclaim + "!</font></center></br>");
    Nobody bother with <script language="JavaScript" type="text/javascript">. I did that already. I am positive that the book that taught me JavaScript said everything I did here was valid. YEAAAH, RIIIGHT!

  8. #8
    Join Date
    Feb 2007
    Location
    North Vancouver, BC, CANADA
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    See, this forum is packed with helpful people!

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

    Default

    This time you're missing quotes But again, it's a lot easier to use arrays.
    Nobody bother with <script language="JavaScript" type="text/javascript">. I did that already.
    Don't bother with language, it's deprecated Just type is fine.
    Code:
    var d = new Date(),
      month = d.getMonth(),
      day = d.getDate(),
      year = d.getFullYear(),
      humanMonth = [
        "January",
        "February",
        "March",
        "April",
        "May",
        "June",
        "July",
        "August",
        "September",
        "October",
        "November",
        "December"
      ][month];
    
    var holidays = {
      '1/1' : ["New Year's Day", "Happy " + year],
      '1/15' : ["Martin Luther King's Birthday", "Feel the freedom"],
      '1/27' : ["The Penguin Popcorn Parade", "Munch, munch, munch"], // What the heck?  Haha.
      '2/2' : ["Groundhog Day", "Let's hope he'll wake up"],
      '2/12' : ["Abraham Lincoln's Birthday", "Goodbye, slavery"],
      '2/14' : ["Valentine's Day", "Feel the love"],
      '2/15' : ["Petentine's Day", "Slurp, slurp, slurp"], // Never heard of this one either...
      '2/22' : ["George Washington's Birthday", "Fly the flag"],
      '3/17' : ["Saint Patrick's Day", "It's hard to find <i>any</i> clovers"], // Not here :-)
      '4/1' : ["April Fool's Day", "My computer is laughing"],
      '4/10' : ["ASPCA's Birthday", "Woof, woof, woof"], // I'm guessing this is the equivalent of RSPCA?
      '4/22' : ["Earth Day", "I think I use too many watts"],
      '6/14' : ["Flag Day", "Someone design an Antarctica flag"],
      '7/4' : ["Independence Day", "Fireworks scare me"],
      '8/29' : ["Henry Bergh's Birthday", "1813?  Yikes"],
      '10/31' : ["Hallowe'en", "Whooooooo"],
      '12/25' : ["Christmas", "Smell the gingerbread"],
      '12/31' : ["New Year's Eve", "Goodbye, " + year]
    };
    
    var holiday = holidays[(month + 1) + "/" + day] || [humanMonth + " " + day, ""];
    
    document.write("It's " + holiday[0] + "!<br><center><font class=exclamation>" + holiday[1] + "!</font></center></br>");
    It was quite entertaining, I've never even heard of some of these American holidays... what exactly happens on the Penguin Popcorn Parade? And what on earth is Petentine's Day? o.@
    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!

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

    Wink Haha.

    Actually, I made Penguin Popcorn Parade and Petentine's Day up.
    ASPCA is indeed the equivalent of RSPCA. (ASPCA = The American Society for the Prevention of Cruelty to Animals.)
    As you might guess, Martin Luther King, George Washington and Abraham Lincoln are some very famous American people...anything else?

    I noticed you updated the humanMonth values. I meant to but never found time.
    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.

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
  •