<a href='#' onClick="fun()"; is not working in IE

P

prathapavp

hi all,

We r working on ERP sys and am doing crossBrowser
compatibility.
The problem is am not able to load one function by onClicking the
refrence text .

could u please help me out.


The code is looking like this........


name="<a href='#' onClick = 'javascript:editCategoryDimmershow123("+id
+");'>"+category.name;+"</a>"
 
Á

Álvaro G. Vicario

(e-mail address removed) escribió:
name="<a href='#' onClick = 'javascript:editCategoryDimmershow123("+id
+");'>"+category.name;+"</a>"

1. Why '#'? Provide a valid alternative URL for the task or just get rid
of the <a> tag.

2. Why 'javascript:'? The onclick attribute expects javascript code, not
an URI.

3. Does it work if you remove the ";" character so you close the <a> tag?
 
V

VK

hi all,

We r working on ERP sys and am doing crossBrowser
compatibility.
The problem is am not able to load one function by onClicking the
refrence text .

could u please help me out.

The code is looking like this........

name="<a href='#' onClick = 'javascript:editCategoryDimmershow123("+id
+");'>"+category.name;+"</a>"

Reason:

http://groups.google.com/group/comp.lang.javascript/msg/eb718930ba71d113

Proper way:

var lnk = document.createElement('A');
lnk.appendChild(document.createTextNode(category.name));
lnk.href = category.name;
lnk.args = {
'id' : id,
// other params if needed
};
lnk.title = popup.helpPrompt // optional
lnk.onclick = editCategoryDimmershow123;
// ...
yourContainer.appendChild(lnk);

with editCategoryDimmershow123 like

editCategoryDimmershow123(e) {
if ((typeof event == 'object') &&
('returnValue' in event)) {
event.cancelBubble = true;
event.returnValue = false;
}
else {
e.stopPropagation();
e.preventDefault();
}
var id = this.args.id;
// do the rest
}

There are other ways as well but this seems the most flexible in
relevance of the arguments.
 
V

vp.softverm

(e-mail address removed) escribió:


1. Why '#'? Provide a valid alternative URL for the task or just get rid
of the <a> tag.

2. Why 'javascript:'? The onclick attribute expects javascript code, not
an URI.

3. Does it work if you remove the ";" character so you close the <a> tag?

--
--http://alvaro.es- Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:http://bits.demogracia.com
-- Mi web de humor al baño María:http://www.demogracia.com
--
hi thanks for the reply actually
i tried with href it was not working that's why i changed
it.
javascript: is for we r refering that function from another js file
thats wy
 
Á

Álvaro G. Vicario

(e-mail address removed) escribió:
hi thanks for the reply actually
i tried with href it was not working that's why i changed
it.
javascript: is for we r refering that function from another js file

Where did you read about that? It doesn't trigger any error but it's of
no use. You can write "godsavethequeen:alert('Hello, World!')" and it'll
still work. I suppose JavaScript considers it a label.
 
V

vp.softverm

Reason:

http://groups.google.com/group/comp.lang.javascript/msg/eb718930ba71d113

Proper way:

var lnk = document.createElement('A');
lnk.appendChild(document.createTextNode(category.name));
lnk.href = category.name;
lnk.args = {
'id' : id,
// other params if needed};

lnk.title = popup.helpPrompt // optional
lnk.onclick = editCategoryDimmershow123;
// ...
yourContainer.appendChild(lnk);

with editCategoryDimmershow123 like

editCategoryDimmershow123(e) {
if ((typeof event == 'object') &&
('returnValue' in event)) {
event.cancelBubble = true;
event.returnValue = false;
}
else {
e.stopPropagation();
e.preventDefault();
}
var id = this.args.id;
// do the rest

}

There are other ways as well but this seems the most flexible in
relevance of the arguments.

hi thanks for the reply
can u bit more specific
actually am tried am getting some errors at " with" if
commented popup not defined n
all,


see this code and try...........

function bG(catid)
{
//alert("showCategories()");
var catArray;
Org.getImmediateSubCategories(catid,{callback:function(cat) {
catArray = cat;
}, async:false});

var header=['','Category Name','Parent
Category','Description','Default Quantity'];
var grid=new OAT.Grid("ngrid_content",0,0);
grid.createHeader(header);
if (catArray.length > 0){
for(var i = 0;i < catArray.length;i++){
Org.getCategory(catArray,{callback:function(category){
var cb;
var name;
var parentId;
var parentName;
var parentName1;
var desc;
var fullQuantity=0;
var image;
var sr1;//src of image
var sr2;

id = category.id;
name="<a href = 'javascript:editCategoryDimmershow123("+id
+");'>"+category.name+"</a>"


parentId = category.parent;
fullQuantity =(category.quantity==""||category.quantity=="null"||
category.quantity==null||
category.quantity==undefined)?"N.A":category.quantity;
desc =(category.desc==""||category.desc=="null"||
category.desc==null||category.desc==undefined)?"N.A":category.desc;
//fullQuantity = category.quantity;
//desc = category.desc;
sr1 = category.image;
sr2 = "images/"+sr1;
//image=' said:

if(parentId != 0){
Org.getCategory(parentId,{callback:function(parent){
parentName = parent.name;
var
rowArr=[cb,name,parentName,desc,fullQuantity];/////////////////////////
vp
grid.createRow(rowArr);
},asyn:true});
}else{
parentName = "Parent";
var rowArr=[cb,name,parentName,desc,fullQuantity];
grid.createRow(rowArr);
}


},asyn:false});
}
} else {
Org.getCategory(catid,{callback:function(category){
var cb;
var name;
var parentId;
var parentName;
var parentName1;
var desc;
var fullQuantity=0;
var image;
var sr1;//src of image
var sr2;

id = category.id;
name="<a href ='#' onClick = 'javascript:editCategoryDimmershow("+id
+"); return false;'>"+category.name;+"</a>"
parentId = category.parent;
fullQuantity =(category.desc==""||category.desc=="null"||
category.desc==null||category.desc==undefined)?"N.A":category.desc;
desc =(category.desc==""||category.desc=="null"||
category.desc==null||category.desc==undefined)?"N.A":category.desc;
sr1 = category.image;
sr2 = "images/"+sr1;
//image=' said:

if(parentId != 0){
Org.getCategory(parentId,{callback:function(parent){
parentName = parent.name;
var rowArr=[cb,name,parentName,desc,fullQuantity];
grid.createRow(rowArr);
},asyn:true});
}else{
parentName = "Parent";
var rowArr=[cb,name,parentName,desc,fullQuantity];
grid.createRow(rowArr);
}


},asyn:false});
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top