SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict crabby80's Avatar
    Join Date
    May 2007
    Posts
    387
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    undefined value from function??

    Hi guys

    Any ideas why this is returning undefined?

    PHP Code:
    function get_question_id(element,needle) {
        
        
    parentElement element.parentNode;
        
        if(
    parentElement.className == needle) {
            for(
    i=0i<parentElement.childNodes.lengthi++) {
                if(
    parentElement.childNodes[i].id == "question_id" ) {
                    
    alert(parentElement.childNodes[i].value); // ok
                    
    return parentElement.childNodes[i].value;
                }
            }
        } else {
            
    get_question_id(parentElement,needle);
        }
    }

    function 
    add_answer(element) {
        
    alert(get_question_id(element,'question')); // undefined


  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Can you show a relevant html code?
    Saul

  3. #3
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
        } else {
            get_question_id(parentElement,needle);
        }
    needs to be
    Code:
        } else {
            return get_question_id(parentElement,needle);
        }
    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.

  4. #4
    SitePoint Addict crabby80's Avatar
    Join Date
    May 2007
    Posts
    387
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Problem solved, thank you for your responses!!


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
  •