Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Feb 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    error:firstChild has no properties in Mozilla.

    Hi everybody,
    me facing issue in cross browser like the below code gives firstChild has no properties in Mozilla.
    and no object found in IE browser...

    i have tried..... sampleXML.item(k).firstChild.nodeValue;
    sampleXML.item(k).firstChild.firstChild.nodeValue;
    sampleXML.item(k).firstChild.nodeValue;
    sampleXML.item(k).childNodes[0].childNodes[0].nodeValue;
    sampleXML.item(k).childNodes[1].childNodes[0].nodeValue;
    but nothing worked for me......
    could anyOne helpme out in fixing this issue....



    Code:
    function selectProjectsForSurvey(){ 
    
        
       	// IE5.2 on Mac OSX doesn't support ActiveXObject
        // So Dom Parser is used to parse, on Mozilla browser
        
       if (document.implementation.createDocument)
            {
                   
            // Mozilla, create a new DOMParser
            parser = new DOMParser();
            var xmlDoc = parser.parseFromString(document.forms[0].projectSurveyMappings.value, "text/xml");
            
            } 
            else if (window.ActiveXObject)
            {
               xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
               xmlDoc.async="false";
               xmlDoc.loadXML(document.forms[0].projectSurveyMappings.value);
            }
           
       	var selectedProjectId = 
    
    document.forms[0].projectId.options[document.forms[0].projectId.selectedIndex].value;
       	if(selectedProjectId < 0){
       	alert("Inside added if...");
       	return " ";
       	}
        var allowNext = false;
    	var projectXML = xmlDoc.getElementsByTagName("PROJECT");
       	var surveyXML;
    	var sampleXML; 
    	
       	
       	for (i=0; i < projectXML.length; i++)
       	{
    		if (projectXML.item(i).getAttribute('id') == selectedProjectId)
    		{
    			surveyXML = projectXML.item(i).getElementsByTagName("SURVEY");
    
    			// Remove all the surveys from the list(associated with previous project)
    			document.forms[0].dataCollectionId.length = 0;
    			
    			for (j=0; j < surveyXML.length; j++)
    			{
    				allowNext = true;
    				var opt = new Option();
    				opt.value = surveyXML.item(j).getAttribute("id");
    				
    				//Line Modified to fix the Mac OSX issue
    	           opt.text =  sampleXML.item(k).firstChild.childNodes[1].childNodes[0].nodeValue;
    
    //the above line has error: firstChild has no properties
    
    				document.forms[0].dataCollectionId[j] = opt;
    
    
    			}
    			sampleXML = projectXML.item(i).getElementsByTagName("SAMPLE"); 
    			document.forms[0].sampleId[0].length = 0;            
    
    			for (k=0; k < sampleXML.length; k++)
    			{
    				 var opt = new Option();
    				 opt.value = sampleXML.item(k).getAttribute("id");
    				 
    				//Line Modified to fix the Mac OSX issue
    				//objXML.text doexn't support on mozilla.	
    				  opt.text = sampleXML.item(k).firstChild.childNodes[1].childNodes[0].nodeValue;				  document.forms[0].sampleId[0][k] = opt;
    			}  
    		}
       	}
    
       	
       	if (allowNext == true)
       		document.forms[0].next.disabled = false;
       	else
       		document.forms[0].next.disabled = true;
       	
       	//document.forms[0].submit();
    }
    
    function onloadForSurvey()
    {
        
    	 selectProjectsForSurvey();
    	if (document.forms[0].dataCollectionId)
    	{
    		if (document.forms[0].dataCollectionId.length == 0)
    	   		document.forms[0].next.disabled = true;
    	   	else
    	   		document.forms[0].next.disabled = false;
    	}
    }

    thanks in advance
    Keerthi
    Last edited by liorean; 02-13-2006 at 04:55 PM. Reason: added [code]code blocks[/code]

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    It sounds like you've encountered the problem of whitespace text nodes. You see, if you have the following XML:
    Code:
    <root>
        <foo>
            <bar>
            </bar>
        </foo>
    </root>
    Then the document tree will look like this:
    Code:
    #element: "root"
    > #text: "\n    "
    > #element: "foo"
    > > #text: "\n        "
    > > #element: "bar"
    > > > #text: "\n        "
    > > #text: "\n    "
    > #text: "\n"
    So, you need to check if the node is a text node, and if so go to the next node.

    Iew doesn't keep text nodes in the DOM as it should.
    Last edited by liorean; 02-13-2006 at 04:55 PM.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    New to the CF scene
    Join Date
    Feb 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi liorean,
    thanks for your kind reply.............

    you are right the node is the text node where i am trying to get the text of the tag

    previously i had used sampleXML.item(k).text
    to get the name of it where it was not supported by the Mac-IE so i changed the code as posted earlier,where the application is working ie the names in the drop down list is changing dynamically....(in 3 drop down according to XML) but i am getting the javascript error saying has no properties

    thanks
    Keerthi

  • #4
    New to the CF scene
    Join Date
    Feb 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    could you please tell me where exactly this below code to be placed i guess the code is correct to get rid off whitespace....

    const notWhitespace = /\S/

    function cleanWhitespace(node) {
    // alert("white Space");
    for (var x = 0; x < node.childNodes.length; x++) {
    var childNode = node.childNodes[x]
    if ((childNode.nodeType == 3)&&(!notWhitespace.test(childNode.nodeValue))) {
    // that is, if it's a whitespace text node
    node.removeChild(node.childNodes[x])
    x--
    }
    if (childNode.nodeType == 1) {
    // elements can have text child nodes of their own
    cleanWhitespace(childNode)
    }
    }
    }

    document.addEventListener("load", function() {
    cleanWhitespace(xmlDoc)
    }, true)


    thanks
    Keerthi

  • #5
    New to the CF scene
    Join Date
    Feb 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    error:firstChild has no properties in Mozilla.

    Hi everybody,
    me facing issue in cross browser like the below code gives firstChild has no properties in Mozilla.
    and no object found in IE browser...

    i have tried..... sampleXML.item(k).firstChild.nodeValue;
    sampleXML.item(k).firstChild.firstChild.nodeValue;
    sampleXML.item(k).firstChild.nodeValue;
    sampleXML.item(k).childNodes[0].childNodes[0].nodeValue;
    sampleXML.item(k).childNodes[1].childNodes[0].nodeValue;
    but nothing worked for me......
    could anyOne helpme out in fixing this issue....

    function selectProjectsForSurvey(){


    // IE5.2 on Mac OSX doesn't support ActiveXObject
    // So Dom Parser is used to parse, on Mozilla browser

    if (document.implementation.createDocument)
    {

    // Mozilla, create a new DOMParser
    parser = new DOMParser();
    var xmlDoc = parser.parseFromString(document.forms[0].projectSurveyMappings.value, "text/xml");

    }
    else if (window.ActiveXObject)
    {
    xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.async="false";
    xmlDoc.loadXML(document.forms[0].projectSurveyMappings.value);
    }

    var selectedProjectId =

    document.forms[0].projectId.options[document.forms[0].projectId.selectedIndex].value;
    if(selectedProjectId < 0){
    alert("Inside added if...");
    return " ";
    }
    var allowNext = false;
    var projectXML = xmlDoc.getElementsByTagName("PROJECT");
    var surveyXML;
    var sampleXML;


    for (i=0; i < projectXML.length; i++)
    {
    if (projectXML.item(i).getAttribute('id') == selectedProjectId)
    {
    surveyXML = projectXML.item(i).getElementsByTagName("SURVEY");

    // Remove all the surveys from the list(associated with previous project)
    document.forms[0].dataCollectionId.length = 0;

    for (j=0; j < surveyXML.length; j++)
    {
    allowNext = true;
    var opt = new Option();
    opt.value = surveyXML.item(j).getAttribute("id");

    //Line Modified to fix the Mac OSX issue
    opt.text = sampleXML.item(k).firstChild.childNodes[1].childNodes[0].nodeValue;

    //the above line has error: firstChild has no properties

    document.forms[0].dataCollectionId[j] = opt;


    }
    sampleXML = projectXML.item(i).getElementsByTagName("SAMPLE");
    document.forms[0].sampleId[0].length = 0;

    for (k=0; k < sampleXML.length; k++)
    {
    var opt = new Option();
    opt.value = sampleXML.item(k).getAttribute("id");

    //Line Modified to fix the Mac OSX issue
    //objXML.text doexn't support on mozilla.
    opt.text = sampleXML.item(k).firstChild.childNodes[1].childNodes[0].nodeValue; document.forms[0].sampleId[0][k] = opt;
    }
    }
    }


    if (allowNext == true)
    document.forms[0].next.disabled = false;
    else
    document.forms[0].next.disabled = true;

    //document.forms[0].submit();
    }

    function onloadForSurvey()
    {

    selectProjectsForSurvey();
    if (document.forms[0].dataCollectionId)
    {
    if (document.forms[0].dataCollectionId.length == 0)
    document.forms[0].next.disabled = true;
    else
    document.forms[0].next.disabled = false;
    }
    }

    const notWhitespace = /\S/

    function cleanWhitespace(node) {
    // alert("white Space");
    for (var x = 0; x < node.childNodes.length; x++) {
    var childNode = node.childNodes[x]
    if ((childNode.nodeType == 3)&&(!notWhitespace.test(childNode.nodeValue))) {
    // that is, if it's a whitespace text node
    node.removeChild(node.childNodes[x])
    x--
    }
    if (childNode.nodeType == 1) {
    // elements can have text child nodes of their own
    cleanWhitespace(childNode)
    }
    }
    }

    document.addEventListener("load", function() {
    cleanWhitespace(xmlDoc)
    }, true)


    i have added function as above to clear the white space could anyoue help me out in fixing this issue...

    thanks in advance
    keerthi

  • #6
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Please don't crosspost. One post is usually enough. Also remember that some kind of issues won't get answers directly, because nobody with both knowledge enough and time enough to spare for it is at it.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards


  •  

    Posting Permissions

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