All pastes #48100 Raw Edit

Untitled

public text v1 · immutable
#48100 ·published 2006-04-04 15:28 UTC
rendered paste body
function loadMonth(month)

{

// load the html file named for the linked month from the current directory and feed it to an inline function

japano.getHTML( month + “.htm”, function(result)

{

            var e=document.getElementById(“thecalendar”);

            // replace the current div with the newly loaded div which has “cpart” as id

            e.parentNode.replaceChild(result,e);

});
}
 

</head>

<body>

<button onclick=”loadmonth(‘may2006’)” title=”May 2006”> &raquo;</button>

<div id=”thecalendar”><table>…</table></div>

</body>

click error:

Line: 22

Char: 1

Error: Object expected

 

 

Load errors:

Line: 277

Char: 13

Error: Expected ‘)’

 

Line: 17

Char: 1

Error: expected ‘)’

 

(as the button loads)

Line: 49

Char: 13

Error: Expected ‘)’

 

(after the calendar loads)

Line: 21

Char: 1

Error: Object expected





*fforw* first some syntax errors..
*fforw* there should be an ; after e.parentNode.replaceChild(result,e)
>fforw< Oh, thought they were optional.  Whoopsie
*fforw* then comes the closing } from the anonymous function..
*fforw* so now you're in the parameters from the japano.getHTML call again
*fforw* close that call with );
>fforw< Where does the extra } go?
*fforw* then you're in the outer function, close that with }
>fforw< Oh! I think I just finally got the concept of the anonymous function.  It's like a mini, inline function?  So the last } should go right after the one that's there?
*fforw* <fforw> make line 17 to
*fforw* <fforw> });
*fforw* <fforw> and add another line after that
*fforw* <fforw> }
*fforw* you need to close the japano.getHTML( call first and add an ; after that
>fforw< Gotcha.
*fforw* everything that's open must be closed in the opposite direction
*fforw* normally you wouldn't put ont onclick for the button into the html..
>fforw< Still wish I knew where that "result" in the parameter comes from.  And the "cpart" stuff?  Does there actually have to be cparts, according to the current syntax?
>fforw< Oh, and how would I activate the thing without a button and an onclick?
*fforw* the cpart is just a leftover from the example.. you don't need that
*fforw* the result is the received HTML element which is then fed to the anonymous function as parameter
*fforw* the anonymous function is needed because js has no threads and stuff
*fforw* so the XMLHTTPRequest goes out, it waits ages (in computer time) and finally receives an HTML result as text.. that gets converted to an element and then the anonymous function is called with it
>fforw< That's what I was thinking.  I didn't know the function getHTML could give the result of its first parameter to the second parameter... But I guess that's why you're awesome.
*fforw* the modern ECMA javascript is really mighty.. and it's very LISPy and stuff..
*fforw* you would normally not setup the button that way..
>fforw< Is there a beginner/intermediate beginner (beginner with harder questions) guide to it anywhere?
*fforw* normally you would make a scriptless working HTML code with some ids to it
>fforw< I didn't really want a button, but the onclick didn't even seem to try working with anything else; although w3schools' guide to javascript says it's supposed to work on spans and such
*fforw* you include the japano.js and your page specific js
>fforw< Ah, use the ids to insert the javascript as the page loads?
*fforw* which includes an japano.event.onload(function() { ... }); that gets executes after the page is loaded
*fforw* in that function you get the references to the stuff you need to add events to and all and do that
*fforw* var button=document.getElementById("calendarButton"); japano.event.add(button, "click", loadMOonth);
*fforw* loadMonth
>fforw<  And I'd make a button with the id "calendarButton"?
*fforw* yep..
*fforw* or an <a>
*fforw* normally you should make sure that the pages also work without js 
*fforw* and make some transforming js that constructs the js page out of the HTML only page
>fforw< I can make an <a> with no href or anything?  Oh.  I guess I'd have to make the js disable the href?
*fforw* that's what now is called "unobtrusive javascript" (good term to goodle for)
>fforw< I will, tomorrow.  If I have time--they've been making me do actual work, at work, instead of projects like the webpage.
*fforw* the event functions you register with japano.event.add
*fforw* are normally of this type
*fforw* function onEvent(e)
*fforw* {
*fforw* }
*fforw* where e is the event in question.. 
*fforw* to prevent the default action the click would have to happen you have to call japano.event.preventDefault(e);
*fforw* (which is missing in the documentation, d'oh)
>fforw< I didn't think I remembered seeing that.
>fforw< Handy, though!