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

loop not working - drop down menu

Status
Not open for further replies.

pampolk

Technical User
Joined
Dec 29, 2002
Messages
10
Location
US
I have an asp program using a drop down menu. For the record in question(I am hardcoding for testing purposes) 2 detail records should be returned. This part is correct.

However because of the way I used coding to populate the drop down menu field(TopicCatagory), I am getting the same value for this field for both detail records. In the database the value for TopicCatagory is different. All other fields that are below are correct.

MeetingDetails ID MeetingID TopicCatagory Notes
20 27 ROP AVON
21 27 ROP RELAY

Where it should be
MeetingDetails ID MeetingID TopicCatagory Notes
20 27 ROP AVON
21 27 PSC RELAY

Below is my code.
--
--<%
OPTION EXPLICIT

'//application variables
dim strSql, db, pcRS, objRs

'//ASSIGN app VALUES
Set db = Server.CreateObject(&quot;ADODB.Connection&quot;)

db.Open &quot;DBQ=&quot; & Server.MapPath(&quot;polk.mdb&quot;) & &quot;;Driver={Microsoft Access Driver (*.mdb)};DriverId=25;MaxBufferSize=8192;Threads=20;&quot;, &quot;username&quot;, &quot;password&quot;

Set pcRS = Server.CreateObject(&quot;ADODB.Recordset&quot;)
Set objRs = Server.CreateObject(&quot;ADODB.Recordset&quot;)

'//do stuff
strSql = &quot;SELECT mt_id, meeting_id, topic_cat_id, topic_id, notes FROM meeting_details WHERE meeting_id = 27 &quot;
pcRS.Open strSql, db

'//meeting variables
dim meeting_id, topic_cat_id

'//init meeting variables
topic_cat_id = pcRS(&quot;topic_cat_id&quot;)
meeting_id = &quot;&quot;
%>

<HTML>
<HEAD>
<TITLE>DropDown Menu</TITLE>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
function submissionHandler(p_oSelWhere) {
// notice the 2 different techniques you can use to do the same thing
if (document.forms[0].topic_cat_id.options[document.forms[0].topic_cat_id.selectedIndex].text == &quot;-- Select Topic --&quot;) {
//if (p_oSelWhere.options[p_oSelWhere.selectedIndex].text == &quot;-- Select Topic --&quot;) {
alert(&quot;Please Select a Topic Category.&quot;);
} else {
// 2 techniques doing the same thing
document.forms[0].topic_catagory.value = p_oSelWhere.options[p_oSelWhere.selectedIndex].text
//document.forms[0].topic_catagory.value = document.forms[0].topic_cat_id.options[document.forms[0].topic_cat_id.selectedIndex].text
document.forms[0].submission.value = &quot;TRUE&quot;
document.forms[0].target = &quot;_self&quot;
document.forms[0].action = &quot;polk.asp&quot;
document.forms[0].submit()
}
}
</SCRIPT>
</HEAD>

<BODY bgcolor=&quot;#97AACF&quot;>
<FORM ID=form1 NAME=form1 METHOD=&quot;POST&quot; ACTION=&quot;polk.asp&quot;>
<INPUT TYPE=&quot;HIDDEN&quot; name=&quot;submission&quot; ID=&quot;submission&quot; VALUE=&quot;&quot;>
<INPUT TYPE=&quot;HIDDEN&quot; name=&quot;topic_catagory&quot; ID=&quot;topic_catagory&quot; VALUE=&quot;&quot;>



<%
'//ADDED THIS TO LOOP THROUGH POSSIBLE MULTIPLE DETAIL RECORDS
'//CORRECT EXCEPT TOPIC_CAT_ID IS THE SAME VALUE
'//RECORD WITH MT_ID 20 -> TOPIC_CATAGORY IS REPORT OF THE PRINCIPAL
'//RECORD WITH MT_ID 21 -> TOPIC_CATAGORY IS PRESENTATION TO THE SCHOOL COUNCIL
'Loop through the recordset
Do While not pcRS.EOF
%>



<center>
<table border=2 width=600>
<TR>
<TD>
Meeting Details ID
</TD>
<TD>
Meeting ID
</TD>
<TD>
Topic Catagory
</TD>
<TD>
Notes
</TD>
</TR>

<TR>
<TD>
<input type=&quot;text&quot; name=&quot;mt_id&quot; maxlength=&quot;4&quot; size=4 value=&quot;<% = pcRS(&quot;mt_id&quot;) %>&quot;>
</TD>

<TD>
<input type=&quot;text&quot; name=&quot;meeting_id&quot; maxlength=&quot;4&quot; size=4 value=&quot;<% = pcRS(&quot;meeting_id&quot;) %>&quot;>
</TD>

<TD>
<%
'//BEGIN TOPIC DROPDOWN
strSql = &quot;SELECT topic_cat_id, topic_catagory FROM topic_catagory&quot;

SET objRs = db.Execute(strSql) '//grab data

'//-topic_id is the NAME/ID of this form element...its VALUE will be the topic_cat_id of the selected topic...the
'// user can't see this'//-the TEXT of this form element will be what the user see's ...the topic_catatory

Response.Write(&quot;<select name='topic_cat_id' id='topic_cat_id' size=1 ONCHANGE='submissionHandler(this)'>&quot;)
do while not objRs.EOF

if topic_cat_id = objRs(&quot;topic_cat_id&quot;) then '//here is where you check with the &quot;other&quot; recordset...the meeting
Response.Write(&quot;<option value='&quot; & TRIM(objRs(&quot;topic_cat_id&quot;)) & &quot;' selected>&quot; & TRIM(objRs(&quot;topic_catagory&quot;)) & &quot;</option>&quot;)
else
Response.Write(&quot;<option value='&quot; & TRIM(objRs(&quot;topic_cat_id&quot;)) & &quot;'>&quot; & TRIM(objRs(&quot;topic_catagory&quot;)) & &quot;</option>&quot;)
end if

objRs.Movenext
loop
Response.Write(&quot;</select>&quot;)
'//END TOPIC DROPDOWN

Response.Write(&quot;<br><br>&quot;)
'Response.Write(&quot;<strong>Request Object Values</strong><br><br>&quot;)
'Response.Write(&quot;Topic Category: &quot; & request(&quot;topic_catagory&quot;) & &quot;<br>&quot;)
'Response.Write(&quot;Topic ID: &quot; & request(&quot;topic_cat_id&quot;))
%>
</TD>

<TD>
<input type=&quot;text&quot; name=&quot;notes&quot; maxlength=&quot;60&quot; size=20 value=&quot;<% = pcRS(&quot;notes&quot;) %>&quot;>
</TD>

</TR>
</table>
</center>

<%
'Move to the next record in the recordset
pcRS.MoveNext
Loop
%>

</form>


</BODY>
</HTML>
--
--
If anyone can point out where I messed up I would so much appreciate it. I could also email the db.

Thank you very much and please everyone have a happy and safe Thanksgiving!

PamPolk


 
can u give us only the Meeting_id code? it makes life easier...

Known is handfull, Unknown is worldfull
 
Here is the code that deals with getting the TopicCatagory.
This hides the topic_cat_id and shows only the topic_catagory.

The topic_cat_id from the main query(pertaining to the record) will populate this drop down. user can then select from the list to change the value if they want to.

The form is used for updating and the TopicCatagory field is required. there will always be a value for this field.

Code:
<%
'//BEGIN TOPIC DROPDOWN
'//This query will enable user to select a value to change 
'//the field if they want to.  Values are 1 PSC/2 ROP/3 
'//OTHER/4 NEW BUSINESS 5/OLD BUSINESS
strSql = &quot;SELECT topic_cat_id, topic_catagory FROM topic_catagory&quot;

SET objRs = db.Execute(strSql)    '//grab data

'//-topic_id is the NAME/ID of this form element...its VALUE will be the topic_cat_id of the selected topic...the 
'// user can't see this'//-the TEXT of this form element will be what the user see's ...the topic_catatory
    
Response.Write(&quot;<select name='topic_cat_id' id='topic_cat_id' size=1 ONCHANGE='submissionHandler(this)'>&quot;)
do while not objRs.EOF
                                            
if topic_cat_id = objRs(&quot;topic_cat_id&quot;) then    '//here is where you check with the &quot;other&quot; recordset...the meeting
  Response.Write(&quot;<option value='&quot; & TRIM(objRs(&quot;topic_cat_id&quot;)) & &quot;' selected>&quot; & TRIM(objRs(&quot;topic_catagory&quot;)) & &quot;</option>&quot;)
else
 Response.Write(&quot;<option value='&quot; & TRIM(objRs(&quot;topic_cat_id&quot;)) & &quot;'>&quot; & TRIM(objRs(&quot;topic_catagory&quot;)) & &quot;</option>&quot;)
end if
                                            
objRs.Movenext
loop
Response.Write(&quot;</select>&quot;)
'//END TOPIC DROPDOWN
%>
--
--
Topic Catagory for MT ID 21 should be Presentation to the School council(If I just use the numeric value for this field, the looping works just fine)
output.jpg



The db /program is very small-I can also send that as a zip file. I am missing something very simple here.

Pam
 
the problem is ur to_cat_id doesnt change for MT ID 20 and 21, so the result for both are the same, how is the top_cat_id determined???

Known is handfull, Unknown is worldfull
 
Yes I agree the top_cat_id is not changing for the record in question.

Top_cat_id is determined by the below sql statment which is in the first posting:

strSql = &quot;SELECT mt_id, meeting_id, topic_cat_id, topic_id, notes FROM meeting_details WHERE meeting_id = 27 &quot;


The second sql statment allows the user to select from a list:

strSql = &quot;SELECT topic_cat_id, topic_catagory FROM topic_catagory&quot;

All I know is if I omit the &quot;concatanation&quot; of the topic_cat_id and topic_catagory and just use topic_cat_id then I get the correct value.

Pam Polk
 
I can now close this thread. Thank you all for posting your comments. I appreciate how helpful this is!

I was told that all I had to do was to move a variable initilaiztion to a different area in the program. So the initialization:

topic_cat_id = pcRS(&quot;topic_cat_id&quot;)

had to be moved to:

Do While not pcRS.EOF
topic_cat_id = pcRS(&quot;topic_cat_id&quot;)
--
--
I never would have caught that!

Thanks again everyone



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top