Click to See Complete Forum and Search --> : Dynamic Drop down to database


Shona Smith
08-18-2006, 04:57 AM
Hi

I have this code which works fine but the second box is not submitted to the database.

Any ideas would be great

<%
' FP_ASP ASP Automatically generated by a Frontpage Component. Do not Edit.
On Error Resume Next

strErrorUrl = ""

If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
If Request.Form("VTI-GROUP") = "0" Then
Err.Clear

Set fp_conn = Server.CreateObject("ADODB.Connection")
FP_DumpError strErrorUrl, "Cannot create connection"

Set fp_rs = Server.CreateObject("ADODB.Recordset")
FP_DumpError strErrorUrl, "Cannot create record set"

fp_conn.Open Application("DropDown3_ConnectionString")
FP_DumpError strErrorUrl, "Cannot open database"

fp_rs.Open "Results", fp_conn, 1, 3, 2 ' adOpenKeySet, adLockOptimistic, adCmdTable
FP_DumpError strErrorUrl, "Cannot open record set"

fp_rs.AddNew
FP_DumpError strErrorUrl, "Cannot add new record set to the database"
Dim arFormFields0(2)
Dim arFormDBFields0(2)
Dim arFormValues0(2)

arFormFields0(0) = "stage2"
arFormDBFields0(0) = "stage2"
arFormValues0(0) = Request("stage2")
arFormFields0(1) = "example"
arFormDBFields0(1) = "example"
arFormValues0(1) = Request("example")

FP_SaveFormFields fp_rs, arFormFields0, arFormDBFields0

FP_SaveFieldToDB fp_rs, Now, "Timestamp"

fp_rs.Update
FP_DumpError strErrorUrl, "Cannot update the database"

fp_rs.Close
fp_conn.Close

FP_FormConfirmation "text/html; charset=windows-1252",_
"Form Confirmation",_
"Thank you for submitting the following information:",_
"ddbasic2.asp",_
"Return to the form."

End If
End If

%>
<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 2</title>
</head>
<body>
<form name="doublecombo" action="--WEBBOT-SELF--" method="POST">
<!--webbot bot="SaveDatabase" SuggestedExt="asp" S-DataConnection="DropDown3" S-RecordSource="Results" U-Database-URL="../../../fpdb/DropDown3.mdb" S-Builtin-Fields="Timestamp" S-Builtin-DBFields="Timestamp" S-Form-Fields="stage2 example" S-Form-DBFields="stage2 example" startspan U-ASP-Include-Url="../../../_fpclass/fpdbform.inc" --><!--webbot bot="SaveDatabase" endspan -->
<p><select name="example" size="1" onChange="redirect(this.options.selectedIndex)">
<option>Departments</option>
<option>CI</option>
<option>PER</option>
</select>
<select name="stage2" size="1">
<option>Cost Centre Codes</option>
<option value="557420">557420</option>
<option value="557123">557123</option>
</select>
<input type="submit" name="test" value="Go!"
onClick="go()">
</p>

<script>
<!--



var groups=document.doublecombo.example.options.length

var group=new Array(groups)
for (i=0; i<groups; i++)
group[i]=new Array()

group[0][0]=new Option("","")
group[0][1]=new Option("557420","")
group[0][2]=new Option("","")

group[1][0]=new Option("557420","")


group[2][0]=new Option("557123","")


var temp=document.doublecombo.stage2

function redirect(x){
for (m=temp.options.length-1;m>0;m--)
temp.options[m]=null
for (i=0;i<group[x].length;i++){
temp.options[i]=new Option(group[x][i].text,group[x][i].value)
}
temp.options[0].selected=true
}

function go(){
location=temp.options[temp.selectedIndex].value
}
//-->
</script>

</form>

</body>


<body>

</body>

</html>

Thanks Shona

metalman3d
08-28-2006, 02:02 PM
This is quite a mess of frontpage code. My first sugguestion is to test to make sure you're passing the variables from the previous page. add the following code just below your body tag so it reads like this:

<body>
<% response.write("variables: " & rFormValues0(0) & "," & rFormValues0(1) & "<br>Requests:" & Request.Form("stage2")& "," arFormValues0(1) = Request.Form("example"))%>
...

if you get nothing on the first line it means the page isn't correctly assigning values to insert into the db. The second line would mean the variables weren't being sent when the page submits. Also, try changing the following code

arFormValues0(0) = Request("stage2")
to
arFormValues0(0) = Request.Form("stage2")

also

arFormValues0(1) = Request("example")
to
arFormValues0(1) = Request.Form("example")


hope it helps.

Shona Smith
08-29-2006, 03:47 AM
Thanks for this

I now get

Microsoft VBScript compilation error '800a03ee'

Expected ')'

/CI/Helpdesk ci/220806/ddbasic2.asp, line 74

response.write("variables: " & arFormValues0(0) & "," & arFormValues0(1) & "<br>Requests:" & Request.Form("stage2")& "," arFormValues0(1) = Request.Form("example"))
-------------------------------------------------------------------------------------------------------------------------^

I also changed this

arFormValues0(0) = Request.Form("stage2")
arFormValues0(1) = Request.Form("example")

Cheers Shona

metalman3d
08-29-2006, 12:55 PM
<% response.write("variables: " & rFormValues0(0) & "," & rFormValues0(1) & "<br>Requests:" & Request.Form("stage2")& "," arFormValues0(1) = Request.Form("example"))%>

I forgot to delete part when I copied the variable name, sorry... :p change it to this...

<% response.write("variables: " & rFormValues0(0) & "," & rFormValues0(1) & "<br>Requests:" & Request.Form("stage2") & "," & Request.Form("example"))%>

Shona Smith
08-30-2006, 02:56 AM
Thanks for this but unfortunately the value from stage2 still doesn't go into the database or show on the confirmation page.

Cheers Shona

metalman3d
08-30-2006, 05:46 PM
Are you seeing the rest of the data? If the stage2 data isn't showing up on the page but you're seeing the rest, the problem may be in the form. Is the name of the input box for the stage2 data actually named stage2?

Shona Smith
08-31-2006, 02:54 AM
Yes it is named stage2

<select name="stage2" language="JavaScript" name="Doublecombo" size="1">
<option>Cost Centre Codes</option>
<option value="557420">557420</option>
<option value="557123">557123</option>
</select>

I picked up the script from here

http://wsabstract.com/script/cut183.shtml

Thanks Shona

metalman3d
08-31-2006, 12:21 PM
<select name="stage2" language="JavaScript" name="Doublecombo" size="1">
------------------^--------------------------------^

You've got it named twice. Try taking out the name="doublecombo". You can also remove the language="javascript" since you have no events on your select.

Shona Smith
09-01-2006, 11:05 AM
OK cheers tried that still no difference.

It's a puzzle!

Have a good weekend
Shona

metalman3d
09-01-2006, 12:05 PM
Well I'm a little stumped. Somehow that stage two variable isn't making it in. My best guess is it has something to do with your form. Wish I could be of more help. If you want to simplify your asp code and feel comfortable writing your own, here's a tutorial on how to write to a database:

http://www.webwizguide.info/asp/tutorials/connecting_to_a_database_pt2.asp

Sorry I couldn't be of more help.

Shona Smith
09-06-2006, 02:51 AM
Just to say thanks for your help anyway

Cheers Shona

russell_g_1
09-06-2006, 03:17 PM
hi shona

have you fixed it? if not then can you view the page in IE (or whatever browser you like), right click it and view source, and then post that up here. that should expose what the problem is in your form.

cheers

russell

Shona Smith
09-07-2006, 03:13 AM
The original code is in the first post this is how it is left after all the help received along the way from metalman3d.

<%
' FP_ASP ASP Automatically generated by a Frontpage Component. Do not Edit.
On Error Resume Next

strErrorUrl = ""

If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
If Request.Form("VTI-GROUP") = "0" Then
Err.Clear

Set fp_conn = Server.CreateObject("ADODB.Connection")
FP_DumpError strErrorUrl, "Cannot create connection"

Set fp_rs = Server.CreateObject("ADODB.Recordset")
FP_DumpError strErrorUrl, "Cannot create record set"

fp_conn.Open Application("DropDown3_ConnectionString")
FP_DumpError strErrorUrl, "Cannot open database"

fp_rs.Open "Results", fp_conn, 1, 3, 2 ' adOpenKeySet, adLockOptimistic, adCmdTable
FP_DumpError strErrorUrl, "Cannot open record set"

fp_rs.AddNew
FP_DumpError strErrorUrl, "Cannot add new record set to the database"
Dim arFormFields0(2)
Dim arFormDBFields0(2)
Dim arFormValues0(2)

arFormFields0(0) = "stage2"
arFormDBFields0(0) = "stage2"
arFormValues0(0) = Request.Form("stage2")
arFormFields0(1) = "example"
arFormDBFields0(1) = "example"
arFormValues0(1) = Request.Form("example")

FP_SaveFormFields fp_rs, arFormFields0, arFormDBFields0

If Request.ServerVariables("HTTP_USER_AGENT") <> "" Then
FP_SaveFieldToDB fp_rs, Request.ServerVariables("HTTP_USER_AGENT"), "Browser_type"
End If
If Request.ServerVariables("REMOTE_HOST") <> "" Then
FP_SaveFieldToDB fp_rs, Request.ServerVariables("REMOTE_HOST"), "Remote_computer_name"
End If
FP_SaveFieldToDB fp_rs, Now, "Timestamp"
If Request.ServerVariables("REMOTE_USER") <> "" Then
FP_SaveFieldToDB fp_rs, Request.ServerVariables("REMOTE_USER"), "User_name"
End If

fp_rs.Update
FP_DumpError strErrorUrl, "Cannot update the database"

fp_rs.Close
fp_conn.Close

FP_FormConfirmation "text/html; charset=windows-1252",_
"Form Confirmation",_
"Thank you for submitting the following information:",_
"ddbasic2.asp",_
"Return to the form."

End If
End If

%>
<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 2</title>
</head>
<body>

<% response.write("variables: " & arFormValues0(0) & "," & arFormValues0(1) & "<br>Requests:" & Request.Form("stage2") & "," & Request.Form("example"))%>

<form name="doublecombo" action="--WEBBOT-SELF--" method="POST">
<!--webbot bot="SaveDatabase" SuggestedExt="asp" S-DataConnection="DropDown3" S-RecordSource="Results" U-Database-URL="../../../fpdb/DropDown3.mdb" S-Builtin-Fields="HTTP_USER_AGENT REMOTE_HOST Timestamp REMOTE_USER" S-Builtin-DBFields="Browser_type Remote_computer_name Timestamp User_name" S-Form-Fields="stage2 example" S-Form-DBFields="stage2 example" U-ASP-Include-Url="../../_fpclass/fpdbform.inc" startspan --><input TYPE="hidden" NAME="VTI-GROUP" VALUE="0"><!--#include file="../../_fpclass/fpdbform.inc"--><!--webbot bot="SaveDatabase" i-checksum="43152" endspan -->
<p><select name="example" size="1" onChange="redirect(this.options.selectedIndex)">
<option>Departments</option>
<option>CI</option>
<option>PER</option>
</select>
<select name="stage2" size="1">
<option>Cost Centre Codes</option>
<option value="557420">557420</option>
<option value="557123">557123</option>
</select>
<input type="submit" name="test" value="Go!"
onClick="go()">



</p>

<script>
<!--



var groups=document.doublecombo.example.options.length

var group=new Array(groups)
for (i=0; i<groups; i++)
group[i]=new Array()

group[0][0]=new Option("","")
group[0][1]=new Option("","")
group[0][2]=new Option("","")


group[1][0]=new Option("557420","")
group[2][0]=new Option("557123","")


var temp=document.doublecombo.stage2

function redirect(x){
for (m=temp.options.length-1;m>0;m--)
temp.options[m]=null
for (i=0;i<group[x].length;i++){
temp.options[i]=new Option(group[x][i].text,group[x][i].value)
}
temp.options[0].selected=true
}

function go(){
location=temp.options[temp.selectedIndex].value
}
//-->
</script>

</form>

</body>


<body>

</body>

</html>
Thanks Shona

russell_g_1
09-10-2006, 08:31 AM
hi shona

something doesn't look right with the javascript. i can see that the second select is being dynamically populated when the first is changed. but when you click the submit button it's running a javascript function called "go", which doesn't appear to do anything useful (just sets a variable).

what we really need to see is the html source not the asp source. so if you open the page in internet explorer and then do "view source" you'll see exactly what the browser is being sent. this should let us see exactly what the asp is producing and hopefully highlight a problem somewhere. (at the moment there are a lot of front page "things" in there that i've not got a clue about)