Help me understand a little javascript

Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Help me understand a little javascript

  1. #1
    Join Date
    Dec 1969
    Posts
    556

    Default Help me understand a little javascript

    Coudl someone do a little commenting on the following insert row function below. I can understnad the basic DHTML Methods getElementByID, insertRow, insertCell.<BR><BR>Where im lost is what does a ? mean, (if arguments.length &#062; 1), i++, arguments[i] etc.<BR> <BR><BR>var table = <BR> document.all ? document.all[tableID] :<BR> document.getElementById(tableID);<BR> if (arguments.length &#062; 1) {<BR> var row = table.insertRow(table.rows.length);<BR> if (document.all) {<BR> for (var i = 1; i &#060; arguments.length; i++) {<BR> var cell = row.insertCell(i - 1);<BR> cell.innerHTML = arguments[i];<BR><BR>Any help would be cool.

  2. #2
    Join Date
    Dec 1969
    Posts
    19,082

    Default RE: Help me understand a little javascript

    arguments is the array of parameters passed to the function<BR>i++ is post fix - it means, basically, use this number, then add one to it.<BR><BR>in context, this code loops through the list of arguments passed to the function and does stuff with them.<BR><BR>what else don&#039;t you get?<BR><BR>(you may find the JScript language reference useful for these questions - http://msdn.microsoft.com/scripting/ )<BR><BR><BR>j<BR>http://rtfm.atrax.co.uk/<BR>

  3. #3
    Join Date
    Dec 1969
    Posts
    556

    Default RE: Help me understand a little javascript

    Thanks Atrax forgot about that baby. Let me get this right, JScript is short for Javascript. Netscape created javascript?<BR><BR>Also with the DOM and DHTML DOM, these are seperate? Can you give me a physically meaning of them. eg a htm doc comes into the browser, where &#060;html&#062; tags are then exposed to the DOM&#039;s residing in the browser??? Am I even close?

  4. #4
    Join Date
    Dec 1969
    Posts
    19,082

    Default RE: Help me understand a little javascript

    &#062; Let me get this right, JScript is short for Javascript. <BR><BR>sort of. JScript is microsoft&#039;s implementation of the ECMAScript language<BR><BR>&#062; Netscape created javascript?<BR><BR>yup. it was called LiveScript originally, but they changed it to javascript to get some piggyback attention during the java boom. Later it was standardised and therefore renamed ECMAScript - the European Computer Manufacturers Association - though in practical terms it&#039;s all just javascript<BR><BR>DOM and dHTML DOM are the same theing, essentially. the DOM is an abstract thing, really. the Document Object Model - it&#039;s a framework for accessing features of an HTML document, basically, in the same way ASP&#039;s Response, Request etc... are a framework for accessing HTTP requests and responses.<BR><BR><BR>j<BR>http://rtfm.atrax.co.uk/<BR>


  5. #5
    Join Date
    Dec 1969
    Posts
    556

    Default DHTML Reference???

    Atrax I dont see any DHTML reference included in the Windows Script V5.6 documentation. Do you know of a download for DHTML????

  6. #6
    Join Date
    Dec 1969
    Posts
    96,118

    Default Dunno about a download...

    ...but:<BR>http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/dhtml_node_entry.asp<BR><BR>This is the page I am constantly starting from:<BR>http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/dhtml_reference_entry.asp<BR><BR>

  7. #7
    Join Date
    Dec 1969
    Posts
    96,118

    Default As for the ? operator...

    ... it&#039;s a kind of shorthand "if ... then....else" thing, but only use in expressions.<BR><BR>For example, you can write a "Max" of two values in JS code easily:<BR><BR> maxOfXandY = ( x &#062; y ) ? x : y;<BR><BR>That says: "If (x &#062; y) is true, then use the value of x, else use the value of y."<BR><BR>That line is equivalent to writing this:<BR> if ( x &#062; y ) maxOfXandY = x; <BR> else maxOfXandY = y;<BR><BR>But that code you show is way obsolete. All current browsers support document.getElementById(), so why bother with the document.all version, at all? [The only oddball in the bunch for most purposes--Netscape 4.x--never did support document.all, which is a purely MSIE thing.]<BR><BR>Just code<BR> var table = document.getElementById(tableID);<BR><BR><BR>

  8. #8
    Join Date
    Dec 1969
    Posts
    556

    Default RE: As for the ? operator...

    Ive got a few Javascript books coming Bible Gold and Definitive Guide which should help me out.<BR><BR>Just on document.all (below is the full function) why has this person used document.all & document.getElementById() in the same function?? Why not stick to one or the other?<BR><BR>Also Bill how do you visualise what the DOM is?<BR><BR>function addRowDOM (tableID) { <BR>// pass every cell content as a futher arg<BR> var table = <BR> document.all ? document.all[tableID] :<BR> document.getElementById(tableID);<BR> if (arguments.length &#062; 1) {<BR> var row = table.insertRow(table.rows.length);<BR> if (document.all) {<BR> for (var i = 1; i &#060; arguments.length; i++) {<BR> var cell = row.insertCell(i - 1);<BR> cell.innerHTML = arguments[i];<BR> }<BR> }<BR> else if (document.getElementById) { <BR>//NN6 bug inserting cells in wrong sequence<BR> for (var i = arguments.length - 1; i &#062;= 1; i--) {<BR> var cell = row.insertCell(arguments.length - 1 - i);<BR> cell.appendChild(document.createTextNode(arguments[i]));<BR> }<BR> }<BR> }<BR>}<BR><BR>&#060;BUTTON ONCLICK="addRowDOM &#039;table1&#039;, &#039;JavaScript.FAQTs.com&#039;, &#039;www.FAQTs.com&#039;);"&#062;<BR>add row per DOM methods<BR>&#060;/BUTTON&#062;

  9. #9
    Join Date
    Dec 1969
    Posts
    96,118

    Default I thought I explained that...

    This is OLD OLD code, from the days of MSIE 3 and NS 3 browsers.<BR><BR>MSIE 3 had document.all[] and NS 3 (or 4?) had document.getElementById(). Neither had the other&#039;s methodology.<BR><BR>So this code:<BR><BR>var table = document.all ? document.all[tableID] <BR> : document.getElementById(tableID);<BR><BR>Is really just shorthand for:<BR><BR>var table;<BR>if ( document.all != null ) table = document.all[tableID];<BR>else table = document.getElementById(tableID);<BR><BR>[The != null isn&#039;t strictly necessary in JS code, but I hate people who leave it out like this guy did, because it just obscures the meaning.]<BR><BR>************<BR><BR>How do I *viualize* the DOM????<BR><BR>Ummmm...it&#039;s a whole bunch of objects that represent various things that are declared/defined via HTML, together with the methods that allow you to manipulate the objects (get and set properties, create new objects, etc., etc.).<BR><BR>I&#039;m not sure what you are asking. If you mean do I have this wonderful 3-D image of the whole thing in my mind, then no way.<BR><BR><BR><BR>

  10. #10
    Join Date
    Dec 1969
    Posts
    556

    Default the Dom

    Bill I think Im just having trouble recogonising where the DOM fits into the scheme of things.<BR>So I take its just like Javascript? Client side, browser dependant?

Posting Permissions

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