www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] error in FF and Chrome with obj.name

Hybrid View

  1. #1
    Join Date
    Mar 2008
    Posts
    54

    resolved [RESOLVED] error in FF and Chrome with obj.name

    Hi!

    My problem is that obj.name, or any of its derivatives do not seem to work in FF and Chrome, but work fine in IE.

    The variable obj stems from
    Code:
    function catchIt(e) {
    	if (editing) return;
    	if (!document.getElementById || !document.createElement) return;
    	if (!e) var obj = window.event.srcElement;
    	else var obj = e.target;
    How come obj.name becomes undefined when i alert it? What can be changed to accommodate the script for FF and Chrome as well?
    The rest of the code:
    Code:
    var editing  = false;
    
    var xmlHttp
    
    
    if (document.getElementById && document.createElement) {
    	var butt = document.createElement('BUTTON');
    	var buttext = document.createTextNode('OK');
    	butt.appendChild(buttext);
    	butt.onclick = saveEdit;
    }
    
    function catchIt(e) {
    	if (editing) return;
    	if (!document.getElementById || !document.createElement) return;
    	if (!e) var obj = window.event.srcElement;
    	else var obj = e.target;
    
    	while (obj.nodeType != 1) {
    		obj = obj.parentNode;
    	}
    	if (obj.tagName == 'TEXTAREA' || obj.tagName == 'A') return;
    	while (obj.nodeName != 'P' && obj.nodeName != 'HTML') {
    
    		obj = obj.parentNode;
    
    	}
    
    	if (obj.nodeName == 'HTML') return;
    	var x = obj.innerHTML;
    	var w = obj.name;
    	var y = document.createElement('TEXTAREA');
    	y.id=obj.id;
    	//y.name = obj.name;
    	alert(w);
    	var z = obj.parentNode;
    	z.insertBefore(y,obj);
    	z.insertBefore(butt,obj);
    	z.removeChild(obj);
    	y.value = x;
    	y.name = w;
    	y.focus();
    	editing = true;
    	area=y;
    
    }
    
    
    function saveEdit() {
    //	var area = document.getElementsByTagName('TEXTAREA')[0];
    	var y = document.createElement('P');
    	var z = area.parentNode;
    	y.name = area.name;
    	//alert(y.name);
    	var iden = area.id;
    	y.id = iden;
    	y.innerHTML = area.value;
    	z.insertBefore(y,area);
    	z.removeChild(area);
    	z.removeChild(butt);
    //	z.removeChild(document.getElementsByTagName('BUTTON')[0]);
    	editing = false;
    
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
      {
      alert ("Browser does not support HTTP Request")
      return
     } 
    
    
    alert(iden+" uppdaterat!");
    //var pidenn=$piden;
    //var pidenn = encodeURIComponent(document.getElementById('pjotor').innerHTML);
    var pidenn = y.name;
    //alert(pidenn);
    alert(y.name);
    var url="extragete.php"
    url=url+"?q="+encodeURIComponent(area.value)+"&id="+pidenn+"&iden="+iden
    url=url+"&sid="+Math.random()
    xmlHttp.onreadystatechange=stateChanged 
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
    
    
    
    function stateChanged() 
    { 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
     { 
    // document.getElementsByTagName('P')[0].innerHTML=decodeURIComponent(xmlHttp.responseText) 
     } 
    }
    function GetXmlHttpObject()
    {
    var xmlHttp=null;
    try
     {
     // Firefox, Opera 8.0+, Safari
     xmlHttp=new XMLHttpRequest();
     }
    catch (e)
     {
     // Internet Explorer
     try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
     catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
     }
    return xmlHttp;
    }
    
    
    
    }
    document.onclick = catchIt;
    
    
    //	var iden = document.getElementsByTagName("P")[0].id;
    /Lorkan

  2. #2
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,122
    you probably need to show the full code it can be troubleshooted. if its not used in its entirety it seem to work in FF
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  3. #3
    Join Date
    Mar 2008
    Posts
    54

    Solution to the obj.name problem!

    Code:
    function catchIt(e) {
    	if (editing) return;
    	if (!document.getElementById || !document.createElement) return;
    	if (!e) var obj = window.event.srcElement;
    	else var obj = e.target;
    
    	while (obj.nodeType != 1) {
    		obj = obj.parentNode;
    	}
    	if (obj.tagName == 'TEXTAREA' || obj.tagName == 'A') return;
    	while (obj.nodeName != 'P' && obj.nodeName != 'HTML') {
    
    		obj = obj.parentNode;
    
    	}
    
    	if (obj.nodeName == 'HTML') return;
    	var x = obj.innerHTML;
    	var w = obj.name;
    	var y = document.createElement('TEXTAREA');
    	y.id=obj.id;
    	//y.name = obj.name;
    	alert(w);
    Code:
    obj.name
    does only seem to work with internet explorer in order to produce the
    Code:
    name="the_name"
    of some html tags (in this case <P>).
    Therefore one should use
    Code:
    title="the_name"
    instead, which works.
    Instead of using obj.name, which for some reason only works in internet explorer you should use
    Code:
    obj.title
    to meddle with the title, or receive its value.
    /Lorkan

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles