Howto loop through table cells in a selection

Ask a Question related to Macromedia Exchange Dreamweaver Extensions, Design and Development.

  1. #1

    Default Howto loop through table cells in a selection

    Hello,

    I'm new to DW development, so I wonder if someone could help me. Say my user
    selects a few cells in a column in a table, and then runs my command. How can
    I loop through the cells in the selection, so that I can read and write the
    text in each cell?

    I realise this is probably trivial if you know your way around the object
    model, but I don't, as yet.

    Many thanks,

    Roger Pearse

    Roger_Pearse Guest

  2. Similar Questions and Discussions

    1. jscript/html. howto address cells
      Hello New to jscript and I want to control where I write output. From examples I can create <img> and give it name and then use js to write to it....
    2. Auto-fill table cells in a selection
      Hello, I'm fairly new to Dreamweaver, but I have an unusual problem, and would be glad for some help. I'm placing online an ancient piece of...
    3. Right justify in all the cells of a table?
      When I try to right justify all of the cells in a table only the right most cells are right justified. Is there any way to right justify all of the...
    4. tabbing between table cells
      Is there a shortcut for "insert end of column" to tab between table cells. Its so clunky. At this rate I think I'll do the tables in a wordprocessor...
    5. background in table cells
      ameen: Yes. Click in the cell and use the Property Inspector to specify a background image. Be aware that in order to see the background fully,...
  3. #2

    Default Re: Howto loop through table cells in a selection

    Roger_Pearse wrote:
    > Hello,
    >
    > I'm new to DW development, so I wonder if someone could help me. Say my user
    > selects a few cells in a column in a table, and then runs my command. How can
    > I loop through the cells in the selection, so that I can read and write the
    > text in each cell?
    >
    > I realise this is probably trivial if you know your way around the object
    > model, but I don't, as yet.
    Try something like the following:
    var dom = dw.getDocumentDOM()
    // grab multiple selections, which corespond to pair's of offsets
    var sel = dom.getSelection(true);

    var objs = new Array();

    for(var i=0;i<sel.length;i+=2){
    // take current selection pair and convert to a tag
    // and stuff into an array to play with
    objs.push(dom.offsetsToNode(sel[i],sel[i+1]));
    }

    // set inertHTML of first node
    objs[0].innerHTML='hello'


    HTH

    --
    Danilo Celic
    | Extending Knowledge Daily : [url]http://CommunityMX.com/[/url]
    | Team Macromedia for Dreamweaver : [url]http://macromedia.com/go/team/[/url]
    danilocelic *TMM* Guest

  4. #3

    Default Re: Howto loop through table cells in a selection

    danilocelic *TMM* wrote:
    > Roger_Pearse wrote:
    > > Hello,
    > >
    > > I'm new to DW development, so I wonder if someone could help me.
    Say my user
    > > selects a few cells in a column in a table, and then runs my
    command. How can
    > > I loop through the cells in the selection, so that I can read and
    write the
    > > text in each cell?
    > >
    > > I realise this is probably trivial if you know your way around the
    object
    > > model, but I don't, as yet.
    >
    > Try something like the following:
    > var dom = dw.getDocumentDOM()
    > // grab multiple selections, which corespond to pair's of offsets
    > var sel = dom.getSelection(true);
    >
    > var objs = new Array();
    >
    > for(var i=0;i<sel.length;i+=2){
    > // take current selection pair and convert to a tag
    > // and stuff into an array to play with
    > objs.push(dom.offsetsToNode(sel[i],sel[i+1]));
    > }
    >
    > // set inertHTML of first node
    > objs[0].innerHTML='hello'
    Many thanks indeed -- I'll experiment.

    All the best,

    Roger Pearse

    roger_pearse@yahoo.co.uk Guest

  5. #4

    Default Re: Howto loop through table cells in a selection

    [email]roger_pearse@yahoo.co.uk[/email] wrote in message news:<1111156512.453612.137340@o13g2000cwo.googleg roups.com>...
    > danilocelic *TMM* wrote:
    > > Roger_Pearse wrote:
    > > > Hello,
    > > >
    > > > I'm new to DW development, so I wonder if someone could
    > > > help me. Say my user selects a few cells in a column in
    > > > a table, and then runs my command. How can I loop
    > > > through the cells in the selection, so that I can read and
    > > > write the text in each cell?
    > > >
    > > > I realise this is probably trivial if you know your way
    > > > around the object model, but I don't, as yet.
    > >
    > > Try something like the following:
    > > var dom = dw.getDocumentDOM()
    > > // grab multiple selections, which corespond to pair's of offsets
    > > var sel = dom.getSelection(true);
    > >
    > > var objs = new Array();
    > >
    > > for(var i=0;i<sel.length;i+=2){
    > > // take current selection pair and convert to a tag
    > > // and stuff into an array to play with
    > > objs.push(dom.offsetsToNode(sel[i],sel[i+1]));
    > > }
    > >
    > > // set inertHTML of first node
    > > objs[0].innerHTML='hello'
    >
    > Many thanks indeed -- I'll experiment.
    Final solution: a file called Chronicon.htm in the c:\program
    files\macromedia\dreamweaver mx\configuration\commands folder.
    Contents:

    ----start of file--
    <html>
    <script language=Javascript>

    //-----------------------------

    function populateCells() {

    var dom = dw.getDocumentDOM()

    // grab multiple selections, which corespond to pair's of offsets
    var sel = dom.getSelection(true);

    var objs = new Array();

    //alert(sel.length/2); //--No of table cells selected

    for(var i=0;i<sel.length;i+=2){
    // take current selection pair and convert to a tag
    // and stuff into an array to play with
    objs.push(dom.offsetsToNode(sel[i],sel[i+1]));
    }

    // Value in first cell. Must subtract zero to force string to
    // numeric.
    var startValue = objs[0].innerHTML - 0;
    if (startValue == 0) {
    alert("First value in selection must contain a numeric");
    return;
    }

    //-- Populate all cells
    for(var i=0;i<sel.length/2;i++){
    // set inertHTML of first node
    objs[i].innerHTML= i + startValue;
    }

    } //--End of populateCells
    //------------------------------

    </script>
    <body OnLoad=populateCells()>
    </body>
    </html>
    ----end of file---

    Many thanks indeed!

    All the best,

    Roger Pearse
    Roger Pearse Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139