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

Discussion in 'Javascript' started by prathapavp@gmail.com, May 21, 2008.

  1. Guest

    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>"
     
    , May 21, 2008
    #1
    1. Advertising

  2. 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?



    --
    -- 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
    --
     
    Álvaro G. Vicario, May 21, 2008
    #2
    1. Advertising

  3. VK Guest

    On May 21, 11:02 am, wrote:
    > 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.
     
    VK, May 21, 2008
    #3
  4. Guest

    On May 21, 12:20 pm, "Álvaro G. Vicario"
    <> wrote:
    > 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?
    >
    > --
    > --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
     
    , May 23, 2008
    #4
  5. 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.


    --
    -- 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
    --
     
    Álvaro G. Vicario, May 23, 2008
    #5
  6. Guest

    On May 21, 12:30 pm, VK <> wrote:
    > On May 21, 11:02 am, wrote:
    >
    > > 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.


    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='<image src="'+sr2+'" width="30px" height="30px" />';
    cb = '<input type="checkbox" name ="cbs" id="cbs" value="'+id+'"/
    >';


    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='<image src="'+sr2+'" width="30px" height="30px" />';
    cb = '<input type="checkbox" name ="cbs" id="cbs" value="'+id+'"/
    >';


    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});
    }
    }
     
    , May 23, 2008
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy Fish
    Replies:
    65
    Views:
    1,825
    Mabden
    May 18, 2004
  2. CRON
    Replies:
    24
    Views:
    203,873
    Adrienne Boswell
    Jun 20, 2006
  3. dolphin
    Replies:
    4
    Views:
    343
    Jorgen Grahn
    Aug 25, 2007
  4. Replies:
    2
    Views:
    637
  5. Vincent van Beveren

    BASE HREF and A HREF="#" onclick="..."

    Vincent van Beveren, Jul 6, 2006, in forum: Javascript
    Replies:
    2
    Views:
    436
    Vincent van Beveren
    Jul 6, 2006
Loading...

Share This Page