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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Type mismatch on a recordset with a hidden field

Status
Not open for further replies.

fergman

Technical User
Oct 19, 2000
91
0
0
US
I'm running into a type mismatch while trying to pass data to a hidden field, or even write it out using response.write, and I don't understand why. The first block of code contains a listbox that populates from a database, the idea is that I want the selected option to assign to the hidden field for use in the next form.

<%
Set Rs = Server.CreateObject(&quot;ADODB.Recordset&quot;)
SQL = &quot;SELECT DISTINCT deplist.department from depList&quot;
Rs.Open SQL, deplist, 1,3

response.write &quot;<select size=&quot;&quot;1&quot;&quot; name=&quot;&quot;Department1&quot;&quot;>&quot;
response.write &quot;<option value=&quot;&quot;Choose&quot;&quot;>&quot;
response.write &quot;</option>&quot;
do while NOT rs.eof
response.write &quot;<option value='&quot; & rs(&quot;department&quot;) & &quot;'>&quot;
response.write rs(&quot;department&quot;)
response.write &quot;</option>&quot;
rs.MoveNext
loop
deptrue=1
response.write &quot;</select>&quot; & &quot;</td>&quot;


this following code block is the hidden field and where the type mismatch appears:
<%
if depTrue = &quot;1&quot; then
response.write rs(&quot;department&quot;) & &quot;the department&quot;
%>
<input type=&quot;hidden&quot; name=&quot;dep1Hidden&quot; value=&quot;<% response.write rs(&quot;department&quot;)%>&quot;>
<%
end if
%>
 
Try displaying the complete code... This is not a bug - it's an undocumented feature...
;-)
 
Hi,

I think you are geeting confused with Server side (ASP)and Client side here. Remember, ASP is trying to build HTML at the server to send back to the client. At the same time you're trying to assign a hidden field a value from a control that hasn't been &quot;built&quot; (or selected) yet.
If you want to dynamically fill a hidden field on the client side you would have to use client side scripting like javascript or VBScript(IE).
HTH
Falcon
 
Ok, firstly you should take the quotes off the 1 in your if check on depTrue. Earlier you set it to the numeric value 1 then you compare it the the string &quot;1&quot;, this is failing.

Second, if it wasn't failing you would be getting a:
Either EOF or BOF is True error when you attempt to print out the department field into your input unless you have done a MoveFirst or MovePrev between the two chunks of code your displaying.

Second and a half, the assignment to the hidden field is mostly unnecessary. If all you want to do is be able to pull the select value out on the next page, use Request.Form(&quot;Department1&quot;). When the form is submitted, the value of the selected option is passed assigned to the select's name. So setting the hidden field will only result in you passing this same data to the next page in two differant variables.

Third, If you still want to assign the value of the hidden field from the select box, Falcon is correct, try to use client-side code in this situation because you want to assign the value of your hidden field after the client (ie browser/person on browser) makes a selection from the select box. If your not to sure how to write the javascript, we can help out with that as well.


Hope this helps,
-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
FAQ FAQ20-2863
= new Forums.Posting.General.GettingAnswers()
 
ok, I ditched the hidden field idea and setup a request.form for the rs(&quot;department&quot;), I dont' know what I was thinking anyway... Here is what I have now:

<%
dep1 = server.htmlencode(request.form(&quot;department1&quot;))

Set deplist = Server.CreateObject(&quot;ADODB.Connection&quot;)
deplist.Provider = &quot;Microsoft.Jet.OLEDB.4.0&quot;
deplist.ConnectionString = &quot;Data Source=&quot; & Server.MapPath (&quot;\data\deplist.mdb&quot;)
deplist.Open

<FORM name=&quot;form1&quot; action=&quot;testloop.asp&quot; method=&quot;post&quot;>

sub getDepartment1()
Set Rs = Server.CreateObject(&quot;ADODB.Recordset&quot;)
SQL = &quot;SELECT DISTINCT deplist.department from depList&quot;
Rs.Open SQL, deplist, 1,3

response.write &quot;<select size=&quot;&quot;1&quot;&quot; name=&quot;&quot;Department1&quot;&quot;>&quot;
response.write &quot;<option value=&quot;&quot;Choose&quot;&quot;>&quot;
response.write &quot;</option>&quot;
do while NOT rs.eof
response.write &quot;<option value='&quot; & rs(&quot;department&quot;) & &quot;'>&quot;
response.write rs(&quot;department&quot;)
response.write &quot;</option>&quot;
rs.MoveNext
loop
response.write &quot;</select>&quot; & &quot;</td>&quot;


set rs=nothing
depTrue = 1
call departmentDone
end sub


sub departmentDone()
if depTrue = 1 then
response.write &quot;<BR>&quot;
response.write dep1 & &quot; dep1&quot;
call getDepartment2
end if

end sub

however now, the dep1 varible is empty when the form submits.
somewhere I missed something. Also the sub getDepartment1 calls the departmentDone sub as soon as it's called it doesn't wait for a selection. is there away around that?
 
Correction, the form fields are submitting fine, it's just the sub calling the other sub without waiting for the user selection that's the problem now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top