Results 1 to 1 of 1

Thread: Undefined Search [DOM]

  1. #1
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default Undefined Search [DOM]

    RESOLVED
    I fixed this by using json, instead of arrays.

    Hello!

    This is kind of javascript and PHP - but the problem has to do with JS.

    I'm creating a suggest search, and a problem I'm facing is that I'm trying to get a variable form another file - and for some reason the javascript isn't gettnig it. =/

    Here's my javascript/html:
    HTML Code:
    <html>
    	<head>
    	  <title>Suggest Search</title>
    	  <script type="text/javascript">
    	    var check, refresh;
    		var headEl = document.getElementsByTagName("head")[0];
    		var suggest = function(me){
    		  // Getting Javascript //
    		  if(check != true){
    		    check = true;
    		  } else {
    		    headEl.removeChild(refresh);
    		  }
    		  refresh = document.createElement("script");
    		  refresh.type = "text/javascript";
    		  refresh.src = "info.php?search="+me.value;
    		  headEl.insertBefore(refresh, document.getElementsByTagName('script')[0]);
    		  // Displaying suggestions //
    		  alert(search.length);
    		};
    	  </script>
    	</head>
    	<body>
    	  <input type="text" onkeydown="suggest(this);" onkeyup="suggest(this);" onchange="suggest(this);" onmouseover="suggest(this);" onclick="suggest(this);"/>
    	</body>
    </html>
    And here's my PHP/javascript:
    PHP Code:
    <?php
    header
    ("Content-type: text/javascript");
    if(!isset(
    $_GET['search'])){ echo 'var search = new Array()'; }
    mysql_connect("localhost""root""") or die(mysql_error());
    mysql_select_db("general") or die(mysql_error());

    $search mysql_real_escape_string($_GET['search']);
    $query mysql_query("SELECT name FROM suggest WHERE name LIKE '%{$search}%'") or die(mysql_error());
    $name = array();
    while(
    $row mysql_fetch_assoc($query)){
      
    $name[] = $row['name'];
    }
    $js_array 'var search = new Array(';
    foreach(
    $name as $key => $value){
      
    $js_array .= ($key == count($name)-1) ? "'$value'" "'$value', ";
    }
    $js_array.= ');';
    echo 
    $js_array;
    ?>
    I'm getting this error:


    If it is needed really badly - I'd be happy to post it online.

    Thanks! Nile
    Last edited by Nile; 01-13-2010 at 12:09 AM.
    Jeremy | jfein.net

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
  •