SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    I'm not a human
    Join Date
    Aug 2006
    Location
    India
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Setattribute not working in IE?

    Hi

    i have a dom code and its working nicely and also in mozilla1.7, firefox but not in IE.

    When i asked this in a forum they told that setattribute property wont work in IE but they have no solution.

    What should i do to have this work in IE??

    the code
    Code:
    var tx1 = document.createElement("input");
    	var tt = document.createTextNode("Enter No. of users:");
    	tx1.setAttribute("name","usersno");
    	tx1.setAttribute("type","text");
    	tx1.setAttribute("maxlength","3");
    	tx1.setAttribute("size","12");
    Regards,
    Vijay
    Follow me on twitter @vijaycbe
    World Holiday Calander || My Cricket Blog

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There's a bug in IE regarding setting the name attribute on elements created with document.createElement(). These describe the solution:
    Death to bad DOM Implementations (Anthony Lieuallen's version of the function)
    Setting the "name" attribute in Internet Explorer
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  3. #3
    I'm not a human
    Join Date
    Aug 2006
    Location
    India
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi

    That's really helped me and

    i tried the following and worked great!!!!!

    Code:
    try {
        var tx1 = document.createElement( '<input name="usersno" MAXLENGTH = 3 onKeyUp = chgdate()>' );
    }
    catch( e ){
        var tx1 = document.createElement("input");
        tx1.setAttribute("name","usersno");
    }
    var tt = document.createTextNode("Enter No. of users:");
    tx1.setAttribute("type","text");
    tx1.setAttribute("maxlength","3");
    tx1.setAttribute("size","12");
    tx1.setAttribute("onKeyUp","chgdate()");
    and the javascript function is called on the key up event also..

    and i'm using same kind of my old code in another page where more 3 or 4 properties are to be set.. that is not working in IE because of the same old damn problem.

    for example i have more properties to be set as

    Code:
    var tx1 = document.createElement("input");
    tx1.setAttribute("name","rate"+localval);
    tx1.setAttribute("type","text");
    tx1.setAttribute("id",localval);
    tx1.setAttribute("readonly",true);
    tx1.setAttribute("class","rjust");
    tx1.setAttribute("value","0.00");
    tx1.setAttribute("size","8");
    I think i can use the same method as creating the elements with the name , property etc...
    but it's not seems to be good to add all properties as a single property for the createelement() function.

    i wish to know is there any other method and any other property specific to IE ,especially in the case of events(such as adding a function call on specific event as onclick="callfunction()" ) and all others..

    Please help me to code better and to make my script in all browsers
    Regards,
    Vijay
    Follow me on twitter @vijaycbe
    World Holiday Calander || My Cricket Blog

  4. #4
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I very rarely use setAttribute(). I prefer the DOM0 syntax.

    These properties are case-sensitive. These should be the correct cases.
    Code:
    tx1.type = "text";
    tx1.maxLength = "3";
    tx1.size = "12";
    tx1.onkeyup = chgdate;
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •