SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast MeLoDi's Avatar
    Join Date
    Sep 2003
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question asp and javascript

    hi there I got this code which was in javascript(http://javascript.internet.com/forms...selection.html ) and I modified it with some asp. Its supposed to show another dropdown menu with dates that belong only to the option that was chosen in the first dropdownbox.

    Code:
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    catnumber = 3
    offset = 150
    performOnchange = false
    if (document.all) {
      docObj = "document.all."
      styleObj = ".style"
      } else {
      docObj = "document."
      styleObj = ""
    }
    function openselect(subcat) {
      popupselect = eval(docObj + subcat + styleObj)
      popupselect.visibility = "visible"
    }
    function closeselect(submenu,subcat){
      popupselect = eval(docObj + subcat + styleObj)
      if (submenu.selectedIndex != 0) {
    	popupselect.visibility = "hidden"
    	numchoice = submenu.selectedIndex
    	choice = submenu[numchoice].value
    	subcategory.value = choice
    	submenu.selectedIndex = 0
      }
    }
    function lock() {
      performOnchange = false
    }
    function unlock() {
      performOnchange = true
    }
    function selectSub(cat) {
      for (i=1; i <= catnumber; i++) {
    	subcat = "sub" + i
    	popupselect = eval(docObj + subcat + styleObj)
    	popupselect.visibility = "hidden"
      }
      if (performOnchange == true) {
    	letsopen = "sub" + cat.selectedIndex
    	if (letsopen == "sub0") {
    	  alert("No category selected")
    	  choice = "- subcategory -"
    	  subcategory.value = choice
    	  cat.focus()
    	  } else {
    	  openselect(letsopen)
    	  lock()
    	}
      }
    }
    //  End -->
    </script>
    
    </HEAD>
    <BODY>
    <select name="purchase" id="purchase" onmouseover="unlock()" onchange="selectSub(this)">
    <option selected value="">- Purchase Invoice -
      <% 
    Dim RS1, sql1, iRecordCount
    sql1 = "SELECT * FROM Bought"
    Set RS1 = objConn.Execute(sql1)
    	 
    iRecordCount = 0
    Do While not RS1.EOF
     %>
      <option value="<%=RS1("BoughtID")%>"><%=RS1("PurchaseInvNo")%></option>
      <%
    iRecordCount = iRecordCount + 1
    RS1.MoveNext
    Loop
    RS1.Close
    Set RS1 = Nothing
    %>
    </select>
    <input type="text" name="subcategory" readonly="readonly" value="- W.E.D -">
    </div>
    
    <div align="center">
    <%
    Dim i 
    i = 0
    For i=1 to iRecordCount
    %>
    <span id="sub<%=i%>">
      <select name="subPurchase" onchange="closeselect(this,'sub<%=i%>')">
    	<option selected value="">- Select W.E.D -
      <% 
    Dim RS3, sql3
    sql3 = "SELECT * FROM Bought Where BoughtID ="&RS1("BoughtID")
    Set RS3 = objConn.Execute(sql3)
    	  
    Do While not RS3.EOF
    		%>
      <option value="<%=RS3("adate")%>"><%(RS3("adate"))%></option>
      <%
    	  RS3.MoveNext
    	   Loop
    	   RS3.Close
    	   Set RS3 = Nothing
    	   %>
    
      </select>
    </span>
    <%next%>
    the thing is i get a Type mismatch with sql3 = "SELECT * FROM Bought Where BoughtID ="&RS1("BoughtID")

    any help would be greatly appreciated.

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Problem is that you have already closed the first recordset at that point, but you are trying to read the ID field from it.

    It looks like you need to do the second query within the first Do While loop.

    Code:
    <div>
    <select name="purchase" id="purchase" onmouseover="unlock()" onchange="selectSub(this)">
    <option selected value="">- Purchase Invoice -
    <% 
    sql1 = "SELECT * FROM Bought"
    Set RS1 = objConn.Execute(sql1)
    	 
    iRecordCount = 0
    sSubPurchases = ""
    Do While not RS1.EOF
    	%><option value="<%=RS1("BoughtID")%>"><%=RS1("PurchaseInvNo")%></option><%
    	
    	sql3 = "SELECT * FROM Bought Where BoughtID ="&RS1("BoughtID")
    	Set RS3 = objConn.Execute(sql3)
    
    	sSubPurchases = sSubPurchases & "<span id=""sub" & iRecordCount & """>"
    	sSubPurchases = sSubPurchases & "<select name=""subPurchase"" onchange=""closeselect(this,'sub" & iRecordCount & "')"">
    	sSubPurchases = sSubPurchases & "<option selected value="""">- Select W.E.D -</option>"
    
    	Do While not RS3.EOF
    		sSubPurchases = sSubPurchases & "<option value=""" & RS3("adate") & """>" & RS3("adate") & "></option>"
    		RS3.MoveNext
    	Loop
    	
    	RS3.Close
    	
    	sSubPurchases = sSubPurchases & "</select></span>"
    	
    	iRecordCount = iRecordCount + 1
    	RS1.MoveNext
    Loop
    %>
    </select>
    <input type="text" name="subcategory" readonly="readonly" value="- W.E.D -">
    </div>
    
    <div align="center">
    <%=sSubPurchases%>
    </div>
    (I didn't test it but that's the idea)

  3. #3
    SitePoint Enthusiast MeLoDi's Avatar
    Join Date
    Sep 2003
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i got rid of the close for the recordset.. but i still don't get it


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •