Sorry for the confusing name, but this is the best I can describe ... So, I have a TD element, and when it double-clicked jQuery, the ajax function returns ul from a PHP script.
New code (sorry for that):
Here is the jQuery Ajax code:
$('#DD_'+IDNum).append('<div class="popUp" id="PU_'+IDNum+'"></div>');
$.ajaxSetup ({
cache: false
});
var ajax_load = '<img class="loading" id="LG_'+IDNum+'" src="../images/loading.gif" />';
if(key==0)
var term = '';
else
var term = $('#TC_'+IDNum).val();
var loadUrl = "./ddGet.php?Ele="+element+"&Client="+ClientID+"&vendorName="+vendorName+"&id="+IDNum+"&term="+term;
$('#PU_'+IDNum+'').html(ajax_load).load(loadUrl);
Here is a PHP snippet:
$result = mysql_query($query) or die(mysql_error());
$response= '<ul id="DD_UL">';
$resultArray = array();
$class = "li-odd";
$i = 1;
while($row = mysql_fetch_array($result))
{
if(!in_array($row[0], $resultArray)){
$resultArray[]=$row[0];
if(isset($row[1]))
$roW1 = ' - '.$row[1];
else
$roW1 = '';
$response .= "\n".'<li id="LI_'.$id.'_'.$i.'" class="'.$class.'">'.$row[0].$roW1.'</li>';
//selectLI(\'LI_'.$id.'_'.$i.'\')
if($class == "li-odd")
$class = "li-even";
else
$class = "li-odd";
$i++;
}
}
$response .= '</ul>';
echo $response;
Here is the response text:
<ul id="DD_UL">
<li id="LI_1_1_1" class="li-odd">E02_02</li>
<li id="LI_1_1_2" class="li-even">E02_03</li>
<li id="LI_1_1_3" class="li-odd">E02_04</li>
<li id="LI_1_1_4" class="li-even">E02_05</li>
<li id="LI_1_1_5" class="li-odd">E02_06</li>
<li id="LI_1_1_6" class="li-even">E02_07</li>
<li id="LI_1_1_7" class="li-odd">E02_08</li>
<li id="LI_1_1_8" class="li-even">E02_09</li>
<li id="LI_1_1_9" class="li-odd">E02_10</li>
<li id="LI_1_1_10" class="li-even">E02_11</li>
<li id="LI_1_1_11" class="li-odd">E02_13</li>
<li id="LI_1_1_12" class="li-even">E02_14</li>
<li id="LI_1_1_13" class="li-odd">E02_20</li>
</ul>
And finally, there will be a new function called after UL that assigns .live:
function selectLI(){
$('#DD_UL').live('click',function(e){
var id = e.target
id = $(id).attr('id');
var IDNum = id.substr(3);
IDNum = IDNum.substring(0,IDNum.lastIndexOf("_"));
var newVal = $('#'+id).html();
if(newVal.indexOf(" - ")>0)
newVal = newVal.substring(0, newVal.indexOf(" - "));
$('#TC_'+IDNum).val(newVal);
});
}
Not so easy, huh? At first, I noticed that in Chrome onclick will only work if it looks like one of the first 4 or so. After the first four (or so) nothing will happen. Then I noticed that FF 3.6 does the same. I am checking IE (although the page is not meant to run in IE) and it worked. Finally, FF 4 works great.
" ", 4,5,6,7... , . , , , .
, .