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 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2009
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    'Undefined' problem

    Hi,
    I'm trying to get to the bottom of a problem & have chosen to temporarily use a button to see what's happening.
    The variable $revnam contains a persons name

    Code:
    echo('<input type="button" onclick="favoriteNumber('.$revnam.')">');
    The simple javascript function looks like this;

    Code:
    function favoriteNumber(myArg) 
    {
    alert(myArg)           
    }
    and the error is;

    Code:
    'TonyBlair' is undefined
    could it be something to do with untrimmed space?
    I haven't got a clue to be honest

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Post your parsed output(html+javascript) taken from browser's view source option.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Jan 2009
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi and thank you for your interest. I'm stumped!

    HTML

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
       <head>
              <link href="book.css" rel="stylesheet" type="text/css">
              <script src="autosuggest.js" type="text/javascript"></script>
              <script src="book.js" type="text/javascript"></script>
              <script src="bookread.js" type="text/javascript"></script>
              <script language="javascript" type="text/javascript">
              function BoxVal()
                   {
                   var bookvar;
                   bookvar = (document.frmone.tb.value);
                   showBOOK(bookvar);
                   }
              </script>
              <script language="javascript" type="text/javascript">
              function favoriteNumber(myArg) {alert(myArg)           }
              </script>
              <title>
              </title>
      </head>
    <body>
    <div id="nav1">
    <a href="http://www.whatever.com/">sometext |</a>
    <a href="http://www.whatever1.com/" target="_blank">sometext |</a>
    <a href="http://www.whatever2.com/" target="_blank">sometext |</a>
    <a href="http://www.whatever3.com/" target="_blank">sometext</a>
    </div>
    <div id="content1">
    <span class="book">Enter data and then click the button</span>
           <form name="frmone" action="">
           <input type='text' style='font-family:verdana;width:300px;font-size:12px' id='tb' Value = "" >
           <script type="text/javascript">
    //XML file loading routine -
    
                   var customarray = new Array();
    //code for IE
                   if (window.ActiveXObject)
                  {
    //alert ('IE')
                             var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
                             xmlDoc.async = false;
                             xmlDoc.load("book.xml");
                  }
    // code for Mozilla, etc.
                  else if (document.implementation && document.implementation.createDocument)
                  {
    //alert ('FF')
                                           var xmlDoc = document.implementation.createDocument("", "", null);
                                           xmlDoc.async = false;
                                           xmlDoc.load("book.xml");
                  }
    // code for other browsers
                  else
                  {
                  alert('Your browser cannot handle this script');
                  }
                  var words = xmlDoc.getElementsByTagName('title');
    //loop through all "title" tags
    //alert (words.length);
                  for (i=0; i < words.length; i++)
                  {
    //add them to the array
                  customarray[i] = words[i].firstChild.nodeValue;
    //alert (customarray[i]);
                  }
    //create the auto-completion text box object
                  new actb('tb', customarray);
                  </script>
                  </form>
    <p>
    <input type="button" id="Button1" value="Read review" onclick="BoxVal()" >
    </p>
    <div id="txtHint"><span class="book">Reviews will appear here.</span></div>
    <div id="txtHint2"><span class="book">Specific reviews will appear here.</span></div>
    </div>
    </body>
    </html>
    PHP

    Code:
    <?php
    echo ('<table class="tablea">');
    $q=$_GET["q"];
    $xmlDoc = new DOMDocument();
    $xmlDoc->load("book.xml");
    $x=$xmlDoc->getElementsByTagName('title');
    for ($i=0; $i<=$x->length-1; $i++)
    {
    
    if ($x->item($i)->nodeType==1)
    {
    if ($x->item($i)->childNodes->item(0)->nodeValue == $q)
        {
        $y=($x->item($i)->parentNode);
        }
    }
    }
    $cd=($y->childNodes);
    
    for ($i=0;$i<$cd->length;$i++)
    {
    if ($cd->item($i)->nodeType==1)
    {
    if($i==7)
      echo ('</td></tr></table><br /><table class="tableb">');
    if($i%8==7)
      echo('<tr><td class="date">');
      else echo('<tr><td class="date2">');
    if($i%8==1 and $i>8)
      $revnam = ($cd->item($i)->childNodes->item(0)->nodeValue);
      echo($cd->item($i)->childNodes->item(0)->nodeValue);
    if($i%8==1 and $i>7)
    echo('&nbsp&nbsp&nbsp&nbsp<a href="javascript:getReaRevs('.$revnam.');">More from this reviewer</a>');
    //the following line (button) is simply a way to find out why $revnam is undefined
    echo('<input type="button" onclick="favoriteNumber('.$revnam.')">');
    }
    }
    echo ('</table>');
    ?>

  • #4
    New Coder
    Join Date
    Jan 2009
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have the solution;

    this is the problem line;

    Code:
    "favoriteNumber('.$revnam.')">');
    it should be;

    Code:
    "favoriteNumber(\''.$revnam.'\')"
    thank you for any interest


  •  

    Posting Permissions

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