Professional Web Applications Themes

Howto loop through table cells in a selection - Macromedia Exchange Dreamweaver Extensions

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 Pe...

  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 Pe

    Roger_Pearse Guest

  2. #2

    Default Re: Howto loop through table cells in a selection

    Roger_Pe 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.getDoentDOM()
    // 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

  3. #3

    Default Re: Howto loop through table cells in a selection

    danilocelic *TMM* wrote:
    > Roger_Pe 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.getDoentDOM()
    > // 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 Pe

    roger_pearse@yahoo.co.uk Guest

  4. #4

    Default Re: Howto loop through table cells in a selection

    [email]roger_peyahoo.co.uk[/email] wrote in message news:<1111156512.453612.137340o13g2000cwo.googleg roups.com>...
    > danilocelic *TMM* wrote:
    > > Roger_Pe 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.getDoentDOM()
    > > // 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.getDoentDOM()

    // 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 Pe
    Roger Pearse Guest

Similar Threads

  1. jscript/html. howto address cells
    By cpanon in forum Macromedia Dynamic HTML
    Replies: 1
    Last Post: October 21st, 08:05 AM
  2. Auto-fill table cells in a selection
    By Roger_Pearse in forum Dreamweaver AppDev
    Replies: 2
    Last Post: March 23rd, 10:43 PM
  3. Tabs in table cells
    By Tony_Stuart@adobeforums.com in forum Adobe Indesign Windows
    Replies: 0
    Last Post: April 1st, 06:04 AM
  4. tabbing between table cells
    By Getho in forum Macromedia Freehand
    Replies: 1
    Last Post: September 22nd, 02:01 AM
  5. background in table cells
    By Murray *TMM* in forum Macromedia Dreamweaver
    Replies: 0
    Last Post: July 10th, 06:06 PM

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
  •  

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