1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

problems with ff and js attribute

Discussion in 'JavaScript' started by progfrog, Jan 20, 2009.

  1. #1
    Hi!
    Does anyone knows how come setAtrribute doesn't work in ff only in ie?

    Is there any replacement for that? any other command?

    thanx a lot
     
    progfrog, Jan 20, 2009 IP
  2. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #2
    really? in FF3.06 just now:
    <a href="#" id="foo">my link</a>
    
    <script language="JavaScript">
    var foo = document.getElementById("foo");
    
    alert(foo.getAttribute("rel")); // alerts null
    foo.setAttribute("rel", "nofollow");
    alert(foo.getAttribute("rel")); // alerts 'nofollow'
    </script>
    
    PHP:
     
    dimitar christoff, Jan 20, 2009 IP
  3. progfrog

    progfrog Peon

    Messages:
    73
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    buy this is the code i wrote that workes well in ie and doesn't work in ff
    Please correct me..

    10x a lot!!


    
    <html>
    <head>
    <script type="text/javascript">
    function regel()
    {
    var z=document.getElementById("t1");
    var s=z.value
    
    document.getElementById("t2").value=s;
    z.setAttribute("value","");
    }
    
    function megel()
    {
    var z=document.getElementById("t2");
    var s=z.value
    
    document.getElementById("t1").value=s;
    z.setAttribute("value","");
    }
    
    
    
    
    
    </script>
    </head>
    <body>
    
    <input type="text" id="t1" style="width:200px; height:200px;">
    <input type="text" id="t2" style="width:200px; height:200px;">
    <input type="button" value="right->>" onclick="regel()"> </button>
    <input type="button" value="<<-Left" onclick="megel()"> </button>
    
    
    </body>
    
    
    
    
    
    
    
    Code (markup):
     
    progfrog, Jan 20, 2009 IP
  4. gnp

    gnp Peon

    Messages:
    137
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    According to the mozilla DOM reference ( https://developer.mozilla.org/en/DOM/element.setAttribute )

    so you should better change your code to
    <script type="text/javascript">
    function regel()
    {
    	var z=document.getElementById("t1");
    	var s=z.value;
    
    	document.getElementById("t2").value=s;
    	z.value="";
    }
    
    function megel()
    {
    	var z=document.getElementById("t2");
    	var s=z.value;
    
    	document.getElementById("t1").value=s;
    	z.value="";
    }
    </script>
    
    HTML:
    hope this helps..
     
    gnp, Jan 20, 2009 IP
    dimitar christoff likes this.
  5. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #5
    interesting, gnp... thanks for that clarification, rep inbound :)
    once again -- sorry for misleading here - this is due to my excessive use of methods and frameworks - in mootools, all i'd do here is element.set("value", "blah"); and forget about it. :(
     
    dimitar christoff, Jan 20, 2009 IP
  6. gnp

    gnp Peon

    Messages:
    137
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Yeah... i did not know about it too...

    just found it :)
     
    gnp, Jan 20, 2009 IP
  7. progfrog

    progfrog Peon

    Messages:
    73
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    thanx foe the information source also..
     
    progfrog, Jan 20, 2009 IP