Ask a Question related to Macromedia Exchange Dreamweaver Extensions, Design and Development.
-
Roger_Pearse #1
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
-
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.... -
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... -
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... -
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... -
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,... -
danilocelic *TMM* #2
Re: Howto loop through table cells in a selection
Roger_Pearse wrote:
Try something like the following:> 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.
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
-
roger_pearse@yahoo.co.uk #3
Re: Howto loop through table cells in a selection
danilocelic *TMM* wrote:
Say my user> Roger_Pearse wrote:> > Hello,
> >
> > I'm new to DW development, so I wonder if someone could help me.command. How can> > selects a few cells in a column in a table, and then runs mywrite the> > I loop through the cells in the selection, so that I can read andobject> > text in each cell?
> >
> > I realise this is probably trivial if you know your way around theMany thanks indeed -- I'll experiment.>> > 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'
All the best,
Roger Pearse
roger_pearse@yahoo.co.uk Guest
-
Roger Pearse #4
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>...
Final solution: a file called Chronicon.htm in the c:\program> 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.
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



Reply With Quote

