Forum Moderators: open

Message Too Old, No Replies

Cant get this ajax suggest to work.

         

NooK

2:35 pm on Mar 4, 2008 (gmt 0)

10+ Year Member



I got this code


<FORM method="POST" id="frmSearch" action="'.$_SERVER['PHP_SELF'].'?action=searchProfile">
<LABEL for="txtSearch"><B>Sök vbcID/Namn:</B></LABEL>
<DIV>
<INPUT type="text" id="txtSearch" name="txtSearch"'.((isset($_REQUEST['txtSearch']) && !empty($_REQUEST['txtSearch']))?' value='.$_REQUEST['txtSearch']:'').' onkeyup="if(event.keyCode != 40 && event.keyCode != 38){ajaxManager(\'search_profile\')};else{document.getElementById(\'search_suggest\').firstChild.focus();}" autocomplete="off">
<INPUT type="submit" id="cmdSearch" name="cmdSearch" value="Search">
<DIV id="search_suggest"></DIV>
</DIV></FORM>

Which as you can see, it runs the ajax function once the user starts typing something in the text field and if the user presses the dow arrow in the search field it should focus the first child of the search div below it (The suggest area).

The ajax function will simple get a string separated by line breaks (\n), break into an array with each line being in an index and loop that array creating child divs under the suggest div for each line, with the code for the for loop being below


var suggest = '<div onmouseover="javascript:suggestOver(this);" ';
suggest += 'onmouseout="suggestOut(this);" ';
suggest += 'onactivate="suggestOver(this);" ';
suggest += 'onkeydown="if(event.keyCode==40)alert this.nextSibling.focus().innerHTML);" ';
suggest += 'onclick="javascript:setSearch(this.innerHTML);" ';
suggest += 'class="suggest_link">' + str[i] + '</div>';
ss.innerHTML += suggest;

With ss above being the suggest div (search_suggest), onmouseover and onactivate will simply call a funcion changing the class of that div to another class to show the selection (diff background color and such), onmouseout will return the class of the selected div back to normal and on keydown should select the div under it.

My problem is that while onmouseover, onmouseout and onclick work, none of the others do.

Onactivate is never called if I mouseover or just press down on the text field and neither is onkeydown.

Anybody got any ideas? I am using IE which apparently doesn't support dynamically DOM changes which is why I have to add the child divs as text.

The idea here is to be able to select the suggestions with either the mouse (Which is working now) and by using the keyboard (It's what I am trying to get to work).

le_gber

4:38 pm on Mar 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Nook, have you tried other 'states'. I am thinking of onfocus for example instead of onactivate?

NooK

8:18 am on Mar 5, 2008 (gmt 0)

10+ Year Member



Yeah I have. Nothing seems to work