|
-
Apr 18th, 2001, 09:54 AM
#1
Thread Starter
Hyperactive Member
Hello,
Please help me with this. Copy this code and view it in your browser.
It has 2 listboxes. The one has the values option1 thru option6 on it and
whatever option you select is then placed in the second listbox. You can
move the selected options from the one listbox to the other as you wish.
You will see that I have a code/specified value for each option in the listbox
eg. option 1 = opt1, option 2 = opt2 etc etc.
My aim with this page is to select certain records (depending on what the user selected)
from a table in my db. Now, I know ASP, but not Java and this is where I need
anyones help. What I want to have is that when the user clicks the submit button, after
selecting whatever options he want, I want to build a sql statement --- something like
"select * from products where prodcode in (var1,var2,var3)" --- where var1,var2,var3
is the "specified value"(eg opt1 or opt2) which the user selected before submitting.
If you can just help me with the code to the point where the sql statement is built -
ie.. after the submit button is clicked, just do a response.write with the correct sql statement
as explained above.
PLEEEASSEEE!! Anyone - I know I'm asking a lot here - and a lot of your time, but I desperately
want to get this going!!
Thanks,
T
.....here's what code I have so far - it works 100% - just copy and paste
code:-
<script language="JavaScript"><!--
function deleteOption(object,index) {
object.options[index] = null;
}
function addOption(object,text,value) {
var defaultSelected = true;
var selected = true;
var optionName = new Option(text, value, defaultSelected, selected)
object.options[object.length] = optionName;
}
function copySelected(fromObject,toObject) {
for (var i=0, l=fromObject.options.length;i<l;i++) {
if (fromObject.options[i].selected)
addOption(toObject,fromObject.options[i].text,fromObject.options[i].value);
}
}
function getIndex(toobject) {
for (var i=toobject.options.length-1;i>-1;i--) {
if (toobject.options[i].selected)
toobject.options[i] = null;;
}
}
//--></script>
<html>
<head>
<title></title>
</head>
<body>
<form>
<table>
<tr>
<td><select name="select1" size="25"
style="font-family: Arial; font-size: 8pt; background-color: rgb(0,0,128); color: rgb(255,255,255); border: medium ridge">
<option value="op1">option1</option>
<option value="opt2">option2</option>
<option value="opt3">option3</option>
<option value="opt4">option4</option>
<option value="opt5">option5</option>
</select> <p> </td>
<td><input type="button" value=" > "
onClick="if (document.images) copySelected(this.form.select1,this.form.select2)"> <p><input
type="button" value=" < " onClick="if (document.images) getIndex(this.form.select2)"> </td>
<td><blockquote>
<p><select name="select2" size="15"
style="font-family: Arial; font-size: 8pt; background-color: rgb(0,0,128); color: rgb(255,255,255); border: medium ridge">
</select> </p>
<p> </p>
<div align="center"><center><p><input type="submit" value="Submit" name="B1"></p>
</center></div>
</blockquote>
</td>
</tr>
</table>
</form>
</body>
</html>
-
Apr 18th, 2001, 02:05 PM
#2
Frenzied Member
Ok. Easy enough. Don't build the SQL statement on the client side. You are going to need to use it on the server side, so build it there. You can either submit, or use querystrings to get the selected data to the server side.
This will work with however-many items are selected:
Code:
Dim strSQL
Dim intLoop
strSQL = "select * from products where prodcode in (" & Request.Form("select1")(1)
If Request.Form("select1").Count > 1 Then
For intLoop = 2 To Request.Form("select1").Count
strSQL = strSQL & ", " & Request.Form("select1")(i)
Next
End If
strSQL = strSQL & ")"
oOOo--oOOo
__ /\/\onte96
oOOo--oOOo
Senior Programmer/Analyst
MCP
[email protected]
[email protected]
Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|