/    Sign up×
Community /Pin to ProfileBookmark

i am writing string in jsp like below

[code]
str = str +
“<a href=”javascript:setCurrentTreeId(‘”+this.id+”‘);” + this.action + “” id=”” + this.id + “-anchor” onfocus=”” onblur=”webFXTreeHandler.blur(this);” onClick=”hcl(‘”+this.action+”‘);”” +
(this.target ? ” target=”” + this.target + “”” : “”) +
“title=”” + tooltip + “”” +
“>” + label + “</a></div>”;

[/code]

its always throwing an javascript error “)” is expected at the onClick function. i don find where i am going wrong. plz suggest me here.
thanks

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Jun 27.2006 — probably would be a lot better if you used ' instead of " or used a variable holding the doble quote instead so it is not as confusing.

If you look at your code you would see "") +

I think you did not mean to do that.

Eric
Copy linkTweet thisAlerts:
@ennidhiauthorJun 27.2006 — actually i am writing this code in js to generate html <href> tag. so its looks to be required to use " ' like javascript:setCurrentTreeId('"+this.id+"'); . in the same way i defined my function like [code=html]onClick="resetTimer('"+this.action+"','"+this.id+"') ;"[/code] . and here it is showing error . i don find any difference between these two.
Copy linkTweet thisAlerts:
@ennidhiauthorJun 27.2006 — i am pasting the mains portion of the code only.
[CODE]



WebFXTree.prototype.toString = function() {
var str = "";
var tooltip = this.text.replace(/"/g,"&quot;");
if (webFXTreeHandler.behavior == 'crn') {
str = str +
"<div id="" + this.id + "" onclick="webFXTreeHandler.toggle(this);" class="webfx-tree-item" onkeydown="return webFXTreeHandler.keydown(this, event)">" +
"<a id="" + this.id + "-icon" class=""+getIconBorderClass(true)+""><div id="" + this.id + "-icon-inner" class=""+getClassNameForIcon(true, this.open)+"">"+getIconInnerText(true, this.open)+"</div></a>"+
"<a href="" + this.action + "" id="" + this.id + "-anchor" onfocus="" onblur="webFXTreeHandler.blur(this);"" +
(this.target ? " target="" + this.target + """ : "") +
"title="" + tooltip + """ +
">" + this.text.toUpperCase() + "</a></div>" +
"<div id="" + this.id + "-cont" class="webfx-tree-container" style="display: " + ((this.open)?'block':'none') + ";">";
} else {
str = str +
"<div id="" + this.id + "" ondblclick="webFXTreeHandler.toggle(this);" class="webfx-tree-item" onkeydown="return webFXTreeHandler.keydown(this, event)">" +
"<img id="" + this.id + "-icon" class="webfx-tree-icon" src="" + ((webFXTreeHandler.behavior == 'classic' && this.open)?this.openIcon:this.icon) + "" onclick="webFXTreeHandler.toggle(this);">" +
"<a href="" + this.action + "" id="" + this.id + "-anchor" onfocus="webFXTreeHandler.focus(this);" onblur="webFXTreeHandler.blur(this);"" +
(this.target ? " target="" + this.target + """ : "") +
"title="" + tooltip + """ +
">" + this.text.toUpperCase() + "</a></div>" +
"<div id="" + this.id + "-cont" class="webfx-tree-container" style="display: " + ((this.open)?'block':'none') + ";">";
}
var sb = [];
for (var i = 0; i < this.childNodes.length; i++) {
sb[i] = this.childNodes[i].toString(i, this.childNodes.length);
}
this.rendered = true;
return str + sb.join("") + "</div>";
};

/*
* WebFXTreeItem class
*/


WebFXTreeItem.prototype.getFirst = function() {
return this.childNodes[0];
}

WebFXTreeItem.prototype.getLast = function() {
if (this.childNodes[this.childNodes.length - 1].open) { return this.childNodes[this.childNodes.length - 1].getLast(); }
else { return this.childNodes[this.childNodes.length - 1]; }
}

WebFXTreeItem.prototype.getNextSibling = function() {
for (var i = 0; i < this.parentNode.childNodes.length; i++) {
if (this == this.parentNode.childNodes[i]) { break; }
}
if (++i == this.parentNode.childNodes.length) { return this.parentNode.getNextSibling(); }
else { return this.parentNode.childNodes[i]; }
}

WebFXTreeItem.prototype.getPreviousSibling = function(b) {
for (var i = 0; i < this.parentNode.childNodes.length; i++) {
if (this == this.parentNode.childNodes[i]) { break; }
}
if (i == 0) { return this.parentNode; }
else {
if ((this.parentNode.childNodes[--i].open) || (b && this.parentNode.childNodes[i].folder)) { return this.parentNode.childNodes[i].getLast(); }
else { return this.parentNode.childNodes[i]; }
} }

WebFXTreeItem.prototype.keydown = function(key) {
if ((key == 39) && (this.folder)) {
if (!this.open) { this.expand(); }
else { this.getFirst().select(); }
return false;
}
else if (key == 37) {
if (this.open) { this.collapse(); }
else { this.parentNode.select(); }
return false;
}
else if (key == 40) {
if (this.open) { this.getFirst().select(); }
else {
var sib = this.getNextSibling();
if (sib) { sib.select(); }
}
return false;
}
else if (key == 38) { this.getPreviousSibling().select(); return false; }
return true;
}

WebFXTreeItem.prototype.toString = function (nItem, nItemCount) {
var foo = this.parentNode;
var indent = '';
if (nItem + 1 == nItemCount) { this.parentNode._last = true; }
var i = 0;
if (webFXTreeHandler.behavior == 'crn') {
while (foo.parentNode) {
foo = foo.parentNode;
indent = "<a id="" + this.id + "-indent-" + i + "" class="indent"><font class="treeIconMinus"></font></a>" +indent;
i++;
}
indent = "<a id="" + this.id + "-indent-" + i + "" class="indent"><font class="treeIconMinus"></font></a>" +indent;
} else {
while (foo.parentNode) {
foo = foo.parentNode;
indent = "<img id="" + this.id + "-indent-" + i + "" src="" + ((foo._last)?webFXTreeConfig.blankIcon:webFXTreeConfig.iIcon) + "">" + indent;
i++;
}
}
this._level = i;
if (this.childNodes.length) { this.folder = 1; }
else { this.open = false; }
if ((this.folder) || (webFXTreeHandler.behavior != 'classic' && webFXTreeHandler.behavior != 'crn')) {
if (!this.icon) { this.icon = webFXTreeConfig.folderIcon; }
if (!this.openIcon) { this.openIcon = webFXTreeConfig.openFolderIcon; }
}
else if (!this.icon) { this.icon = webFXTreeConfig.fileIcon; }
var label = this.text.replace(/</g, '&lt;').replace(/>/g, '&gt;');
var tooltip = this.text.replace(/"/g,"&quot;");
var str = "";
if (webFXTreeHandler.behavior == 'crn') {
str = "<div id="" + this.id + "" onclick="webFXTreeHandler.toggle(this);" class="webfx-tree-item" onkeydown="return webFXTreeHandler.keydown(this, event)">" +
indent +
"<a id="" + this.id + "-plus" class=""+getIconBorderClass(this.folder)+""><div id="" + this.id + "-plus-inner" class=""+getClassNameForIcon(this.folder, this.open)+"">"+getIconInnerText(this.folder, this.open)+"</div></a>"+

"<a id="" + this.id + "-icon" style="display:none;"></a>";

if (this.action == null) {
str = str +
"<a id="" + this.id + "-anchor" onfocus="" onblur="" style="color: gray;" " +
"title="" + tooltip + """ +
">" + label + "</a></div>";
} else {
str = str +
"<a href="javascript:setCurrentTreeId('"+this.id+"'); onClick="resetTimer('"+this.action+"','"+this.id+"') ;"" + this.action + "" id="" + this.id + "-anchor" onfocus="" onblur="webFXTreeHandler.blur(this);" onClick="resetTimer('"+this.action+"','"+this.id+"') ;" " +
(this.target ? " target="" + this.target + """ : "") +
"title="" + tooltip + """ +
">" + label + "</a></div>";
}
} else {
str = "<div id="" + this.id + "" ondblclick="webFXTreeHandler.toggle(this);" class="webfx-tree-item" onkeydown="return webFXTreeHandler.keydown(this, event)">" +
indent +
"<img id="" + this.id + "-plus" src="" + ((this.folder)?((this.open)?((this.parentNode._last)?webFXTreeConfig.lMinusIcon:webFXTreeConfig.tMinusIcon):((this.parentNode._last)?webFXTreeConfig.lPlusIcon:webFXTreeConfig.tPlusIcon)):((this.parentNode._last)?webFXTreeConfig.lIcon:webFXTreeConfig.tIcon)) + "" onclick="webFXTreeHandler.toggle(this);">" +
"<img id="" + this.id + "-icon" class="webfx-tree-icon" src="" + ((this.open)?this.openIcon:this.icon) + "" onclick="webFXTreeHandler.select(this);">";
"<a href="javascript:setCurrentTreeId('"+this.id+"');" + this.action + "" id="" + this.id + "-anchor" onfocus="webFXTreeHandler.focus(this);" onblur="webFXTreeHandler.blur(this);" onClick="resetTimer('"+this.action+"','"+this.id+"') ;" " +
(this.target ? " target="" + this.target + """ : "") +
">" + label + "</a></div>";
}
str = str +
"<div id="" + this.id + "-cont" class="webfx-tree-container" style="display: " + ((this.open)?'block':'none') + ";">";
var sb = [];
for (var i = 0; i < this.childNodes.length; i++) {
sb[i] = this.childNodes[i].toString(i,this.childNodes.length);
}
this.plusIcon = ((this.parentNode._last)?webFXTreeConfig.lPlusIcon:webFXTreeConfig.tPlusIcon);
this.minusIcon = ((this.parentNode._last)?webFXTreeConfig.lMinusIcon:webFXTreeConfig.tMinusIcon);
return str + sb.join("") + "</div>";
}




[/CODE]
×

Success!

Help @ennidhi spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...