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!

check box comparison continued

Status
Not open for further replies.

stpmtp

MIS
Jan 6, 2006
67
US
Good Morning,

I have been following this thread 333-1223333

I am kind of in the same boat as nonprogrammer.

I was able to find a javascript that redirects to an asp page when you check a checkbox.

Up to this point is all well and good, but when I try to pass the variable to the asp page that is where I am having a problem.

Could anyone help please?

Javascript (this page is saved as an html page)

Code:
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />


<script language="JavaScript"><!--
function redirect (form, group) {
  var numberClicked = 0;
  for (var i=0; i<form.elements.length; i++) {
    if (form.elements[i].name == group && form.elements[i].type == 'checkbox' && form.elements[i].checked)
      numberClicked++;
  }
  if      (numberClicked <= 3) url = 'view1.asp'
  else if (numberClicked <= 6) url = 'view1.asp';
  else                         url = 'view1.asp';
  location.href = url;
  return false;
}
//--></script>

</head>

<body>

<form onSubmit="return redirect(this,'group1')">
<input type="checkbox" name="part1">
<input type="checkbox" name="group1">
<input type="checkbox" name="group1">
<input type="checkbox" name="group1">
<input type="checkbox" name="group1">
<input type="checkbox" name="group1">
<input type="checkbox" name="group1">
<input type="checkbox" name="group1">
<input type="checkbox" name="group1">
<input type="submit" value="Submit">
</form>

</body>

</html>

Then I took Tarwn suggestion

Code:
strSQL = "SELECT productName, width, height, etc FROM Products WHERE productID IN (" & Request.Form("MyCheckboxField") & ")"

and I did this
Code:
Dim jschkbx = request.querystring("part1")
strSQL = "SELECT productName, width, height, etc FROM Products WHERE productID IN (" & Request.Form("MyCheckboxField") & ")"

This is where I am having problems passing the variable

here is what the asp page looks like took this from nonprogrammer


Code:
<%



'Dimension variables
jschkbx = request.querystring("part1")
Dim adoCon 			'Holds the Database Connection Object
Dim myrs			'Holds the recordset for the record to be updated
Dim strSQL			'Holds the SQL query for the database
Dim lngRecordNo			'Holds the record number to be updated

'Read in the record number to be updated
lngRecordNo = CLng(Request.QueryString("ID"))

'Create an ADO connection odject
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("db/Partsearch.mdb")

'Set an active connection to the Connection object using DSN connection
'adoCon.Open "DSN=guestbook"

'Create an ADO recordset object
Set myrs = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the database
   
strSQL = "SELECT * From Parts WHERE ID IN (" & Request.Form("jschkbx") & ")"


'Open the recordset with the SQL query 
myrs.Open strSQL, adoCon
%>
</head>
<script language="JavaScript" type="text/JavaScript">
<!--


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
//-->
</script>
<style type="text/css">
<!--
body {
	background-color: #FFFFFF;
}
-->
</style><body text="#339933" link="#33FF00" vlink="#666666" alink="#666600" onLoad="MM_preloadImages('file:///P|/Inetpub/[URL unfurl="true"]wwwroot/aqpc/wb/images/overview.gif')">[/URL]
<!-- Begin form code -->
<p><img src="file:///P|/Inetpub/[URL unfurl="true"]wwwroot/aqpc/wb/images/dvlg.png"[/URL] width="217" height="87"> </p>
<p>&nbsp;</p><form name="form" method="post" action="comparisonprocess.asp">
<table width="100%" border=".25">
  <tr>
    <td width="15%"><img src="<%= myrs.Fields("pic")%>"></td>
    <td width="32%">
      <p>Part Number</p>
        <p>
          <%Response.Write ("<a href=""updateform.asp?id=")
        Response.Write (myrs("id"))
        Response.Write (""">" & myrs("id") & "</a>")%>
        </p>        </td>
      <td width="1%">&nbsp; </td>
    <td width="17%"><%response.write (myrs("SubCategory"))%> </td>
    <td width="1%"><%response.write (myrs("Diameter"))%> </td>
    <td width="1%"><%response.write (myrs("height"))%></td>
    <td width="1%"><%response.write (myrs("hub"))%></td>
    <td width="1%">&nbsp;</td>
    <td width="1%">&nbsp;</td>
    <td width="1%">&nbsp;</td>
    <td width="1%">&nbsp;</td>
    <td width="1%">&nbsp;</td>
    <td width="1%">&nbsp;</td>
    <td width="1%">&nbsp;</td>
    <td width="1%">&nbsp;</td>
    <td width="1%">&nbsp;</td>
    <td width="1%">&nbsp;</td>
    <td width="1%">&nbsp;</td>
    <td width="1%">&nbsp;</td>
    <td width="20%">&nbsp;</td>
  </tr>
</table>
  <p align="center"><strong>
    <input type="submit" name="Submit" value="Submit">
    </strong></p>
<table border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
	<td><!--DWLayoutEmptyCell-->&nbsp;</td>
  </tr>
</table>
<table width="505" border="0">
  <!--DWLayoutTable-->
  <tr> 
    <td width="227" height="46" valign="top"><div align="center"><strong></strong> 
      </div></td>
    <td width="7"></td>
    <td width="257"></td>
  </tr>
  <tr>
    <td height="12"></td>
    <td></td>
    <td></td>
  </tr>
  <tr> 
    <td height="46" colspan="2" valign="top"><div align="center"> </div></td>
    <td></td>
  </tr>
</table></form>
<body>
<p>&nbsp;</p>
<div align="center"> </div>
</body>
</html>

<%
'Reset server objects
myrs.Close
Set myrs = Nothing
Set adoCon = Nothing
%>
 
I forgot to mention this is the error I get
Code:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'ID IN ()'.
/search/view1.asp, line 34
 
You do not have a field on your form named MyCheckboxField so you cannot get the value from it on your ASP page.
What should the value be? The total number of boxes checked or something else? You need to store that value in a hidden form field of the same name you are checking for in your asp page.

You also do not specify the form action or method on your form page. Even if you are changing the location it will send to you should specify a default location just for the sake of standards.
You will want to have method="post" in order to use Request.Form or method="get" to use Request.Querystring.

Simplify things first. Instead of calling your page to run a SQL query, first verify that you are receiving the value you expected. Make your page very simple like this:
Code:
<%
  myVar = Request.Form("MyCheckboxField")
  Response.Write "Checkbox value: " & myVar
%>

If you get the value then it is not with the form submitting.

However,

It's hard to think outside the box when I'm trapped in a cubicle.
 
theniteowl ,

I tried that and either I am doing something wrong or it did not work.
 
I made a number of comments. Which one do you refer to when you say you tried it? Your code will NOT work if it is looking for a field that does not actually exist so you have to start with your HTML and javascript code before you can begin testing your ASP.


It's hard to think outside the box when I'm trapped in a cubicle.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top