If you have sorted the options in the prompt, you can capture the keypress events to build a string as the user types. Use that string to compare to the values in the options array. You can set the first option that startsWith that string as selected.
If you really want to show only the values that match the user input (rather than select the first one in alpha order), you'll need to keep the full set of possible options somewhere in (probably) another array to do more processing with it for each keypress, then repopulate the prompt.
HTH,
Joe
I don't understand the need for java script based on your explanation. The search and select prompt will, by default, return values starting with the value typed by the user. From the list of items returned, the user then selects one (or more if it is multi-select) as the criteria.
So if you want to automatically select all the searched values (because, lets face it, having a user click on "select all" is just too much to ask of them </sarcasm> ) then why use search and select at all? Just use a type in prompt and filter using a like clause in the query.
I have seen situations with clients where some developer (who is long gone and never wrote a scrap of documenation) was being ulta-clever with java script so that reports could almost get up and wash the windows for you. Come upgrade time the reports are broken and the client has a mess on their hands trying to fix or re-write things that could have been done without java script in the first place. Sorry for the preaching...
Sorry for the trouble.
I didn't check it properly. After that I have checked it. That's available there itself.
Anyway thanks to you all for your valuable raplies.
Actually my requirement is not exactly that. You can find my exact requirement below.
--------------------------------------
Hi all,
I have a search and select prompt. If type any word in the search box it should show the list of values starting with that word in a dropdown list like GOOGLE.
For Example : If start to type in GOOGLE it will show some related strings starting with that word.
Like that it should show in our Search and select prompt.
Is it possible with Java Script. If its possible please give me the code.
Your help will be appreciated.
Thanks in advance..........
Quote from: Sarayucog on 05 Oct 2010 01:45:32 AM
Sorry for the trouble.
I didn't check it properly. After that I have checked it. That's available there itself.
Anyway thanks to you all for your valuable raplies.
Actually my requirement is not exactly that. You can find my exact requirement below.
--------------------------------------
Hi all,
I have a search and select prompt. If type any word in the search box it should show the list of values starting with that word in a dropdown list like GOOGLE.
For Example : If start to type in GOOGLE it will show some related strings starting with that word.
Like that it should show in our Search and select prompt.
Is it possible with Java Script. If its possible please give me the code.
Your help will be appreciated.
Thanks in advance..........
Hi Sarayucog
That search which is used in Google is called 'Live search' which is actually based on some JavaScript/Ajax and PHP .
Then only it is possible to same type of look and feel in your search, i think it is bit complex to implement in reports. if you want to implement you should have a knowledge on how to fetch and hold the data item values Dynamically(using XML) from the content store before executing a report query prior to report run time
Because in live search The page on the server called by the JavaScript above is a PHP file called.The PHP searches an XML file for titles(Here XML need to hold the data item values from the content store dynamically)
---------------------------------------------------------------------------------------
Sample ScriptsJAVA SCRIPT CODE
-----------------------------------------------
<html>
<head>
<script type="text/javascript">
function showResult(str)
{
if (str.length==0)
{
document.getElementById("livesearch").innerHTML="";
document.getElementById("livesearch").style.border="0px";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("livesearch").innerHTML=xmlhttp.responseText;
document.getElementById("livesearch").style.border="1px solid #A5ACB2";
}
}
xmlhttp.open("GET","livesearch.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<input type="text" size="30" onkeyup="showResult(this.value)" />
<div id="livesearch"></div>
</form>
</body>
</html>
PHP CODE
------------------------------------------------
<?php
$xmlDoc=new DOMDocument();
$xmlDoc->load("links.xml");
$x=$xmlDoc->getElementsByTagName('link');
//get the q parameter from URL
$q=$_GET["q"];
//lookup all links from the xml file if length of q>0
if (strlen($q)>0)
{
$hint="";
for($i=0; $i<($x->length); $i++)
{
$y=$x->item($i)->getElementsByTagName('title');
$z=$x->item($i)->getElementsByTagName('url');
if ($y->item(0)->nodeType==1)
{
//find a link matching the search text
if (stristr($y->item(0)->childNodes->item(0)->nodeValue,$q))
{
if ($hint=="")
{
$hint="<a href='" .
$z->item(0)->childNodes->item(0)->nodeValue .
"' target='_blank'>" .
$y->item(0)->childNodes->item(0)->nodeValue . "</a>";
}
else
{
$hint=$hint . "
<a href='" .
$z->item(0)->childNodes->item(0)->nodeValue .
"' target='_blank'>" .
$y->item(0)->childNodes->item(0)->nodeValue . "</a>";
}
}
}
}
}
// Set output to "no suggestion" if no hint were found
// or to the correct values
if ($hint=="")
{
$response="no suggestion";
}
else
{
$response=$hint;
}
//output the response
echo $response;
?>