Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Dynamic Dropdown issue
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Dynamic Dropdown issue

 Post Reply Post Reply Page  12>
Author
simflex View Drop Down
Groupie
Groupie
Avatar

Joined: 10 November 2002
Location: United States
Status: Offline
Points: 63
Post Options Post Options   Thanks (0) Thanks(0)   Quote simflex Quote  Post ReplyReply Direct Link To This Post Topic: Dynamic Dropdown issue
    Posted: 17 July 2003 at 9:47am

<html>
<head>
<language=javascript>
function setOptions(optSelect) {
var selbox = document.frmNew.Section;

selbox.options.length = 0;
if (optSelect == " ") {
  optSelect.options[optSelect.options.length] = new Option('Please select one of the options above first',' ');
    }


if (optSelect == "ORG") {
   <%
   'lets queueu up the recordset, check if it has records, then output some options
   If NOT staffset.EOF Then staffset.MoveFirst
   Do Until staffset.EOF
      'lets dynamically add to the javascript
      Response.Write "selbox.options[selbox.options.length] = new Option('" & staffset("empid") & "','" & staffset("lname") & "');" & vbCrLf
      staffset.MoveNext
   Loop
   %>
   }
  
 }
</script>

</head>
<body>
Set emailDB = Server.CreateObject("ADODB.Connection")
emailDB.Open "dsn=to_odbc"
<form name=frmNew action=insertRec method=post>
  <table>
    <tr>
      <td>Name of Affected Deputy Director?</td>
      <td> <select name="staff" onchange="setOptions(document.frmNew.staff.options[document.frmNew.staff.selectedIndex].value);">
        <OPTION value="invalid choice" SELECTED>&lt;Choose One&gt;</OPTION>
          <%
sql = "SELECT theEmp.empID, theEmp.LName+', '+theEmp.FName as fullname FROM theEmp WHERE theEmp.TypeID = 2"
set staffset = emailDB.execute(sql)
while not staffset.eof
%>
   <option value="<%=staffset(0)%>"><%=staffset(1)%></option>
  <%
 staffset.Movenext
 wend
 staffset.close
 set staffset = nothing

    %>
  </select></td>
</tr>
</table>
</form>
</body>
</html>

Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 17 July 2003 at 10:24am
Am I missing something or...? Where are you putting your records into an array? You should use staffset("empID") and staffset("Fullname") to get the values.
Back to Top
simflex View Drop Down
Groupie
Groupie
Avatar

Joined: 10 November 2002
Location: United States
Status: Offline
Points: 63
Post Options Post Options   Thanks (0) Thanks(0)   Quote simflex Quote  Post ReplyReply Direct Link To This Post Posted: 17 July 2003 at 11:50am

hi Michael,

when I put the javascript code between the head  <head></head>of the html code, I get "object required" script error.

If I put it just below this line:

Set emailDB = Server.CreateObject("ADODB.Connection")
emailDB.Open "dsn=to_odbc"

I get:

"expected statement 

<language="javascript">" error even after this:

      Response.Write "selbox.options[selbox.options.length] = new Option('" & staffset("empid") & "','" & staffset("fullname") & "');" & vbCrLf

I am not sure where these pieces of code should be placed.

 

Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 17 July 2003 at 12:14pm

i think (and this is by looking at the above code) that you don't understand that the ASP's VBscript runs on the server before the html gets put to the client....

so right off the bat, you need to take the ADODB.Connection and the call to fill the recordset to the very top of the page so that is availabel when it tries to Response.Write out the javascript that will then be run on the client.......

 

Contribute to the working anarchy we fondly call the Internet
Back to Top
KCWebMonkey View Drop Down
Senior Member
Senior Member
Avatar
Go Chiefs!

Joined: 21 June 2002
Status: Offline
Points: 1319
Post Options Post Options   Thanks (0) Thanks(0)   Quote KCWebMonkey Quote  Post ReplyReply Direct Link To This Post Posted: 17 July 2003 at 6:32pm
Also, make sure that your ASP code is between <% and %> or it will not be viewed as server side script.
Back to Top
simflex View Drop Down
Groupie
Groupie
Avatar

Joined: 10 November 2002
Location: United States
Status: Offline
Points: 63
Post Options Post Options   Thanks (0) Thanks(0)   Quote simflex Quote  Post ReplyReply Direct Link To This Post Posted: 18 July 2003 at 7:08am

*************************************************

i think (and this is by looking at the above code) that you don't understand that the ASP's VBscript runs on the server before the html gets put to the client....

*****************************************

I do and I had the adodb and the call at the top in my original code.

Sometimes when you try what you know to solve a problem and is not working, then you begin to tinker with the code to see if you can get lucky and resolve the problem.

Such was the case with me with this code.

Well, I have put it back at the top and I am still getting this error"

"object required" around this code:

If NOT staffset.EOF Then staffset.MoveFirst
   Do Until staffset.EOF
      'lets dynamically add to the javascript
      Response.Write "selbox.options[selbox.options.length] = new Option('" & staffset("empid") & "','" & staffset("lname") & "');" & vbCrLf
      staffset.MoveNext
   Loop
This is frustrating.

If I do a static dropdown where the values are hardcoded, it works but I have to do it this way because there is an email program attached to my code which sends email based on someone's empid.

If I do it static, the empid will have to be removed.

Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 18 July 2003 at 8:12am

again.. you are declaring/filling the recordset "staffset" at the bottom of the page

but you are trying to use it at the very top of the page... the ASP engine has absolutely no idea what "staffset" is at that point.. you must declare the connection, open the connection, delcare the recordset, open the recordset, THEN you can use it....

your code is totally out of order

Contribute to the working anarchy we fondly call the Internet
Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 18 July 2003 at 8:21am

heres the code redone

http://www.morningz.com/sections/playground/files/code/proper_flow.zip

no idea if it works since i dont have your database... also fixed the script block for javascript that you had tagged wrong

Contribute to the working anarchy we fondly call the Internet
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.