Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dropdown search query

Status
Not open for further replies.

nomu26

Programmer
Sep 10, 2003
22
ZA
I have created a form to perform a search with dropdowns and textboxes, I want the user to select any search criteria, if all is selected it works fine but if you select some of the fields it return an error :Microsoft JScript runtime error: object doesn't support this property or method, here's the code:

<script language="javascript" type="text/javascript">
var wMyWindow;
function MoreInfo(sValue)
{
sValue = sValue +'?qstrEntityCode=' + document.frmSalesReport.cboEntity.options[document.frmSalesReport.cboEntity.selectedIndex].value + '&qstrEntity=' + document.frmSalesReport.cboEntity.options[document.frmSalesReport.cboEntity.selectedIndex].text + '&qstrVolumeNo=' + document.frmSalesReport.cboVolumeNo.options[document.frmSalesReport.cboVolumeNo.selectedIndex].value + '&qstrUseCode=' + document.frmSalesReport.cboUseCode.options[document.frmSalesReport.cboUseCode.selectedIndex].value + '&qstrRateCode=' + document.frmSalesReport.cboRateCode.options[document.frmSalesReport.cboRateCode.selectedIndex].value + '&qstrHomogeneousCode=' + document.frmSalesReport.txtHomogeneousCode.value + '&qstrBlockPlan=' + document.frmSalesReport.txtBlockPlan.value;
var bName = navigator.appName;
var bVer = parseInt(navigator.appVersion);
if (sValue.length > 1)
{
if (wMyWindow && (((bName.indexOf("Netscape") > -1) && (bVer > 2)) || ((bName.indexOf("Explorer") > 0) && (bVer > 2))))
{
if (!wMyWindow.closed)
{
wMyWindow.close();
}
}
wMyWindow = window.open(sValue ,'_blank');
}
}
</script>
<form>
<TR>
<TD align="center" bgColor="#9cb0be" colSpan="2"><A href="javascript:MoreInfo('SalesAnalysisReportView.aspx');"><IMG id="IMG1" alt="Submit" src="../images/submit.gif" align="absMiddle" border="0" runat="server"></A>
</TD>
</TR>
</form>

if someone can tell me what's wrong with my query string cause i've even tried testing one by one it still gives me the error but if I select everything it returns no errors.

thanks
cheers
 
You cannot get options[selectIndex] when nothing is selected, as that is that same as asking for options[-1], which will clearly fail.

You need to build up your query string bit-by-bit, after testing to see if each select box has an item selected (i.e. selectedIndex != -1).

Hope this helps,
Dan
 
thanks for replying Billy but what i also want is to build the query in such a way that it works even if the user doesn't select all
 
Try this alternative:

Code:
<script language="javascript" type="text/javascript">
<!--
	var wMyWindow;
	function MoreInfo(sValue) {
		var frm = document.frmSalesReport;
		var tempStr = '?qstrEntityCode=';
		tempStr += (frm.cboEntity.selectedIndex == -1) ? frm.cboEntity.options[frm.cboEntity.selectedIndex].value : '';
		tempStr += '&qstrEntity=' + 
		tempStr += (frm.cboEntity.selectedIndex == -1) ? frm.cboEntity.options[frm.cboEntity.selectedIndex].text : '';
		tempStr += '&qstrVolumeNo=' + 
		tempStr += (frm.cboVolumeNo.selectedIndex == -1) ? frm.cboVolumeNo.options[frm.cboVolumeNo.selectedIndex].value : '';
		tempStr += '&qstrUseCode=' + 
		tempStr += (frm.cboUseCode.selectedIndex == -1) ? frm.cboUseCode.options[frm.cboUseCode.selectedIndex].value : '';
		tempStr += '&qstrRateCode=' + 
		tempStr += (frm.cboRateCode.selectedIndex == -1) ? frm.cboRateCode.options[frm.cboRateCode.selectedIndex].value : '';
		tempStr += '&qstrHomogeneousCode=' + frm.txtHomogeneousCode.value + '&qstrBlockPlan=' + frm.txtBlockPlan.value;

		sValue += tempStr;
		var bName = navigator.appName;
		var bVer = parseInt(navigator.appVersion);
		if (sValue.length > 1) 
		{
			if (wMyWindow && (((bName.indexOf("Netscape") > -1) && (bVer > 2)) || ((bName.indexOf("Explorer") > 0) && (bVer > 2))))
			{
				if (!wMyWindow.closed)
				{
					wMyWindow.close();
				}
			} 
			wMyWindow = window.open(sValue ,'_blank');
		}
	}        
//-->
</script>

Also, I can't help but notice the following line:

Code:
if (sValue.length > 1)

The length of sValue will always equal more than 1 anyway, because of the strings that are being added... So you can remove this redundant check.

Hope this helps,
Dan
 

Aaargh...copy paste error there, sorry!... This is the correct version:

Code:
<script language="javascript" type="text/javascript">
<!--
	var wMyWindow;
	function MoreInfo(sValue) {
		var frm = document.frmSalesReport;
		var tempStr = '?qstrEntityCode=';
		tempStr += (frm.cboEntity.selectedIndex == -1) ? frm.cboEntity.options[frm.cboEntity.selectedIndex].value : '';
		tempStr += '&qstrEntity=';
		tempStr += (frm.cboEntity.selectedIndex == -1) ? frm.cboEntity.options[frm.cboEntity.selectedIndex].text : '';
		tempStr += '&qstrVolumeNo=';
		tempStr += (frm.cboVolumeNo.selectedIndex == -1) ? frm.cboVolumeNo.options[frm.cboVolumeNo.selectedIndex].value : '';
		tempStr += '&qstrUseCode=';
		tempStr += (frm.cboUseCode.selectedIndex == -1) ? frm.cboUseCode.options[frm.cboUseCode.selectedIndex].value : '';
		tempStr += '&qstrRateCode=';
		tempStr += (frm.cboRateCode.selectedIndex == -1) ? frm.cboRateCode.options[frm.cboRateCode.selectedIndex].value : '';
		tempStr += '&qstrHomogeneousCode=' + frm.txtHomogeneousCode.value + '&qstrBlockPlan=' + frm.txtBlockPlan.value;

		sValue += tempStr;
		var bName = navigator.appName;
		var bVer = parseInt(navigator.appVersion);
		if (sValue.length > 1) 
		{
			if (wMyWindow && (((bName.indexOf("Netscape") > -1) && (bVer > 2)) || ((bName.indexOf("Explorer") > 0) && (bVer > 2))))
			{
				if (!wMyWindow.closed)
				{
					wMyWindow.close();
				}
			} 
			wMyWindow = window.open(sValue ,'_blank');
		}
	}        
//-->
</script>

Dan
 
thank you so much BillyRay, i finally got it to work with your help ofcourse

thanks a million
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top