hi,
I have been trying to populate a HTML list tag dynamically using javascript. The idea is to fetch data from LDAP using my PHP code. I would then pass on this data as a string to my javascript function, which in turn would display my HTML list with the required Options.
Well, I have been playing around with a simpler code snippet. i.e i am not considering the LDAP-part as of now. I am unable to get the code do the right stuff. My code looks like :
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<BODY>
<?php
$idstring = '';
$idarr = Array("amit","bala", "Amrita", "sangita", "Ajay", "Sagar", "mahesh");
sort($idarr);
foreach ($idarr as $id)
{
$idstring .= $id.'|';
echo "IDSTRING : $idstring <br>";
}
?>
<form name="form1" action="">
Testing <BR>
<!--Enter Name : <INPUT Type=name onKeyUp="return display(this, '<?php echo $idstring ?>')"> <BR> -->
Enter Name : <input id="strstart" name="strstart" value="" size="40" maxlength="255" type="text" onKeyUp="return display(this,'<?=$idstring;?>')"> <br>
Mail ID List : <select multiple name ="idlist">
<option value="first">First Option</option>
</select>
</form>
</BODY>
</HTML>
<script>
function display(obj, names)
{
var sellist = document.forms['form1'].idlist;
//convert all values to lowercase for comparisions
var currVal = obj.value.toLowerCase() ;
//split the names using the separator, this returns array
var arrVal = names.split("|");
sellist.options.length = 0;
for (i = 0;i < arrVal.length;i++)
{
compval = arrVal[i].toLowerCase();
if (compval.indexOf(currVal) == 0)
{
sellist.options[i] = new Option(arrVal[i],arrVal[i]);
}
else
{
sellist.options[i] = null;
}
}
}
</script>
Can somebody help me out with this ?
Thanx !
-mahesh.