Question on Custom HTML Search Button on Home Page: I know that the field needs to be the field id which is 29. However, I cannot seem to get the script to work to search that field. When I run the search it returns all records.

  • 0
  • 1
  • Question
  • Updated 6 years ago
  • Answered
<script type="text/javascript">
function SrchSubmit()
{
var searchforthis=document.getElementById("searchforthis").value;url="bhhpd6xjp?a=s&query=({'29'.CT.'" + searchforthis + "'})";location.href = url;
}
</script>
<table> <tbody> <tr>
<td><strong><font color="#0f11ff">Search For: </font></strong></td>
<td>
<input style="margin-right: 15px;" id="searchforthis" /></td>
<td>
<input style="font: bold 12px/normal Arial; width: 135px; font-size-adjust: none; font-stretch: normal;" onclick="SrchSubmit()" value="Search" type="button" /></td> </tr> </tbody></table>

Photo of Dawn

Dawn

  • 0 Points

Posted 6 years ago

  • 0
  • 1
Photo of dwhawe

dwhawe, Champion

  • 908 Points 500 badge 2x thumb
I know the Pirate will have a much better answer but it may be that you are using CT which is contains.

Depending on your specific use, it may be to ambiguous.
Photo of Dawn

Dawn

  • 0 Points
well i changed to EX for exact and it didnt' work either.   :-(
Photo of Dawn

Dawn

  • 0 Points
the EX still pulled every record as well...
Photo of dwhawe

dwhawe, Champion

  • 908 Points 500 badge 2x thumb
My script skills are extremely weak. One other suggestion is change the "s" to a "q" after the "="
?a=q&query
Photo of Dawn

Dawn

  • 0 Points
ohhhh, was optimistic but it didn't work either.  Thank you for all your help though... Keep them coming if have you more ideas!
Photo of QuickBasePros (Laura Thacker)

QuickBasePros (Laura Thacker), Champion

  • 5,406 Points 5k badge 2x thumb
Another good way to see if you're using the right commands, is to build a report with the filter you want, and then look at the expanded URL of the report under the More option to see if you are getting all the components correct.
Photo of KenFirch

KenFirch

  • 10 Points
Looks right to me too.   As QuickbasePros_IDS suggests, let's see what the expanded URL for a sample report using a contains operation for field 29 looks like.
Photo of Dawn

Dawn

  • 0 Points
Thanks!  The expanded URL on the report giving me the filtered info is:  
?a=q&qt=tab&dvqid=1000000&query=({'29'.EX.'New'})&opts=nos.

I still cannot get it to work.  The button still brings back all records and I've changed from CT to EX just for testing.  I think I will enter a support case... I'm sure I'm just mising something, but I can't get it to work and our users would really like this if i can put it on each of our table pages for searching.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,224 Points 20k badge 2x thumb
Your code works for me (I tested it). Although I could suggest several improvements, the problem probably lies with incorrect parameters or some type of typo. I would manually generate the URL you think your code should produce for a given search term and examine the results of pasting this URL into the browser address bar.
Photo of KenFirch

KenFirch

  • 10 Points
You could try this modified version that does a quick API_DoQueryCount first to determine how many records will be returned by the search. If it is zero then a screen won't open with zero records. Uncomment the alert line (remove the //) and see if the record count matches what you are seeing on your report.

<script type="text/javascript">
function SrchSubmit()
{
var searchforthis = document.getElementById("searchforthis").value;
var qrystr = "{'29'.CT.'" + searchforthis + "'}";
var url = "bhhpd6xjp?act=API_DoQueryCount&query=" + qrystr;
$.get(url, function(xml) {
if($("errcode", xml).text() == "0") {
var recs = parseInt($("numMatches", xml).text());
// alert(recs + " matching records found.");
if(recs==0) {
alert("No records matching '" + searchforthis + "' were found.");
}else{
url="bhhpd6xjp?a=s&query=" + qrystr;
location.href = url;
}
}else{
alert("Query error: " + $("errtext", xml).text());
}
});

}
</script>
<table> <tbody>
<tr>
<td><strong><font color="#0f11ff">Search For: </font></strong></td>
<td>
<input style="margin-right: 15px;" id="searchforthis " /></td>
<td>
<input style="font: bold 12px/normal Arial; width: 135px; font-size-adjust: none; font-stretch: normal;" onclick="SrchSubmit()" value="Search" type="button" /></td>
</tr> </tbody>
</table>