This topic is locked
[SOLVED]

 Automatically search "Between" dates on Advanced

8/8/2011 7:19:58 PM
PHPRunner General questions
C
copper21 author

Hello All,
I am trying get the advanced search page to search between two dates using the "between" option. I have a sql datetime field called "red_TimeStamp" and would like it when someone goes to the advanced search page for this field to automatically have selected "between" and the two search fields to be popuplated; the first one with a date 2 weeks prior to todays date and the second one to have todays date in it. I have followed a previous post, http://www.asprunner.com/forums/topic/12907-default-date-range-advanced-search/ with no luck. I have PHP Runner 5.3 and am using Microsoft SQL as my database. Here is the code I have based off of that post:
global

$red_TimeStamp_editcontrol,$red_TimeStamp_editcontrol1;

$red_TimeStamp_editcontrol["params"]["value"] = date("Y-m-d",strtotime("-2 week"));

$red_TimeStamp_editcontrol1["params"]["value"] = date("Y-m-d");

// write search options

$opt = "Between";

$options="";

$options.="<OPTION VALUE=\"Equals\" ".(($opt=="Equals")?"selected":"").">Equals</option>";

$options.="<OPTION VALUE=\"More than\" ".(($opt=="More than")?"selected":"").">More than</option>";

$options.="<OPTION VALUE=\"Less than\" ".(($opt=="Less than")?"selected":"").">Less than</option>";

$options.="<OPTION VALUE=\"Between\" ".(($opt=="Between")?"selected":"").">Between</option>";

$options.="<OPTION VALUE=\"Empty\" ".(($opt=="Empty")?"selected":"").">Empty</option>";

$searchtype = "<SELECT ID=\"SearchOption\" NAME=\"asearchopt_red_TimeStamp\" SIZE=1 onchange=\"return ShowHideControls();\">";

$searchtype .= $options;

$searchtype .= "</SELECT>";

$searchtype;

$xt->assign("searchtype_red_TimeStamp",$searchtype);
I am getting an error " 'get(...)'is null or not an object" from IE.
If it matters, the "View As" setting is datetime.
Thanks for any help.

Sergey Kornilov admin 8/10/2011

This method is specific to an older version of PHPRunner and won't work with PHPRunner 5.3.
Here is a better option. Add this code to Javscript OnLoad event of the Search page. This code snippet assumes that your date field name is 'Date Listed'.

$("#srchOpt_1_Date_Listed").val('Between');

$("#srchOpt_1_Date_Listed").trigger('change');

var ctrl = Runner.getControl(pageid, 'Date Listed');

var d1 = new Date();

d1.setDate(d1.getDate() - 14);

ctrl.setValue(d1);
var ctrl2 = Runner.controls.ControlManager.getAt(false, 1, 'Date Listed',1);

var d2 = new Date();

ctrl2.setValue(d2);
C
copper21 author 8/10/2011

Sergey,
Worked like a charm...many thanks to you!