sharal Posted November 27, 2009 Share Posted November 27, 2009 It can be discussed whether this is actually, an issue with my php. But as i'm in doubt, i'll post it here. Who knows, most of you do probably have some experience with javascript as well. You do not need to worry about the xml http request object or anything, because that works. What i'm trying to do, is returning a div with an id that is generated via the php script. That also works perfectly well, however javascript doesn't seem to be reading the innerHTML that is dynamically returned. Enough talking, here's what i think you need of the php code to understand the problem: <?php $base = ''; $i = 0; while($row = mysql_fetch_assoc($query)) { $i++; $base .= '<div id="highlight'.$i.'" onclick="swap(highlight'.$i.')">' . $row['suggest'] . '</div>'; /* $base is succesfully returned to the auto_suggest tab. that works * Notice the click function, thats what's making trouble. Basically it's parsing the id with it in the swap function * So that it will be easy to extract with javascript.. or? */ } echo $base; return $base; ?> and here's the javascript: // javascript. function swap (fid) { document.getElementById("search").value = document.getElementById(fid).innerHTML; } so, i would now expect the swap(fid) to be - for instance swap(highlight1) and so on. Which it should be, but for some reason, fid appears to be undefined. To make it perfectly clear, what i want to do is: The server returns a response in a list below the search field, (now heres the problem) and when i click that div where the response is contained in, the response from that div is supposed to go into my search field (search). i've attached an image of how it looks. [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/183106-some-help-with-an-auto-complete-function/ Share on other sites More sharing options...
sharal Posted November 27, 2009 Author Share Posted November 27, 2009 Looks like javascript function values must look like this: swap('highlight1'); - so the single quotes are missing, just need php to return it with single quotes now then. Link to comment https://forums.phpfreaks.com/topic/183106-some-help-with-an-auto-complete-function/#findComment-966373 Share on other sites More sharing options...
sharal Posted November 27, 2009 Author Share Posted November 27, 2009 ended up with this work around, it outputs the string as it's supposed to - well nearly. It causes javascript to stop executing because of some error, but nevertheless the auto complete on click works. <?php $str1 = '<div id="highlight'.$i. '"'; $str2 = 'onclick="swap'; $str3 = "('highlight$i')"; $str4 = '>' . $row['suggest'] . '</div>'; $base = $str1 . $str2 . $str3 . $str4; ?> Link to comment https://forums.phpfreaks.com/topic/183106-some-help-with-an-auto-complete-function/#findComment-966382 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.