:: Forum >> Version 2 >>

Is it possible to change ID onfly

More information on this topic is available in the documentation section: /aw.system.html/setid.html.

Is it possible to change object ID's (setID) onfly?
Oddbjørn
Thursday, April 10, 2008
Yes, sure. Maybe I don't understand your question - could you explain what you are trying to do?
Alex (ActiveWidgets)
Thursday, April 10, 2008

Eks.

1. I have made a button with id='oldname' written to HTML.
2. Then I have a visual userinterface where the user can change all kind of (AW.UI) properties of the button.
3. And I want to give the user ability to change the id to what ever they want eks. 'newname'.

Maybe it is easier to show in codes, what I want.

function (oldname,newname){
var oldobj=AW.object("oldname");
oldobj.setId("newname");
oldobj.refresh();
}

The "new named" object is not working correctly anymore.

Thanks
Oddbjørn
Thursday, April 10, 2008
Oddbjørn, I am also not sure of the intention:

in your code shouldn't it read ?
function SOMETHING(oldname,newname){  And if oldname and newname are parameters, shouldn't it be into the function without doublecuotes ?
var oldobj=AW.object(oldname);
oldobj.setId(newname); 
I made the simplest sample trying to discover what's wrong, and found
that oldobj.setId(newname) is thowing an alert. (but the rest seems ok to me)
Alex, is this normal ?
var obj = new AW.UI.Grid
obj.setId('grid1');
obj.setCellText(function(i,j){return '-' i}); 
obj.setHeaderText(function(i){return 'header-'+ + i}); 
obj.setColumnCount(4); 
obj.setRowCount(5); 
document.write(obj ); 

var 
DivOne = new AW.HTML.DIV;
DivOne.setId('d1');
document.write(DivOne ); 

var 
Ab2 = new AW.UI.Button
Ab2.setId('hhh'); 
Ab2.onControlClicked = function(){
changeId'grid1''NEW-ID');
}
 
document.write(Ab2 ); 

function 
changeId(oldname,newname){
var 
oldobj=AW.object(oldname);
oldobj.setId("newname");
oldobj.onCellClicked = function(){ alert(this.getId())}
DivOne.setContent('html'oldobj.toString());
DivOne.refresh();
Carlos
Thursday, April 10, 2008
Thanks alot, but a little embarassed. It's so simple.

I had tested it before, and I didn't get the old object away, and I don't think you got the old object away (it's just a copy with new name and with lost connection).

Still:
1. I put the "old" grid inside DivOne right away
2. Then I changed the name your way

It seems to be perfect.

Thanks again.



Oddbjørn
Friday, April 11, 2008
The unique id is used to find the html element which corresponds to the given AW object. So if you want to change the id, you have to remove old html element and insert new one with the new id.
Alex (ActiveWidgets)
Friday, April 11, 2008



This topic is archived.

Back to /aw.system.html/setid.html

Documentation:

Forum search