Notices

Great community. Great ideas.

Welcome to ASP/Free, a community dedicated to helping beginners and professionals alike in improving their knowledge of Microsoft's development and administration technologies. Sign up today to gain access to the combined insight of tens of thousands of members.

Thread: Classic ASP within Javascript

Results 1 to 4 of 4
Share This Thread →
  1. #1
    mark.shawe is offline Registered User
    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Classic ASP within Javascript

    Hi,

    I am trying to place the following in a javascript.

    It works when it is not in a loop, but when it is in a loop it gets the last record instead of the one that it relates to in the loop, any ideas on how to get this to work in a loop environment?

    Code:
    Code:
    <% For intRec=1 To rsMaterials.PageSize
    				If Not rsMaterials.EOF Then %>
    				<%
    				Set rsCategoryDetails = Server.CreateObject("ADODB.Recordset")
    				strCategoryDetails = "SELECT ID, title, order FROM materialsCategories WHERE ID = " & rsMaterials("category") & ""
    				rsCategoryDetails.Open strCategoryDetails, adoCon
    					
    				Set rsSupplierDetails = Server.CreateObject("ADODB.Recordset")
    				strSupplierDetails = "SELECT ID, active, company, phone, fax, email, addressPhysicalStreet, addressPhysicalSuburb, addressPhysicalPostalCode, addressPhysicalCity, addressPostalStreet, addressPostalSuburb, addressPostalPostalCode, addressPostalCity, createdBy, created, updatedby, updated FROM suppliers WHERE ID = " & rsMaterials("supplier") & ""
    				rsSupplierDetails.Open strSupplierDetails, adoCon
    		
    				Set rsPerMeasurementDetails = Server.CreateObject("ADODB.Recordset")
    				strPerMeasurementDetails = "SELECT ID, title, titleMultiples, order FROM materialsPerMeasurement WHERE ID = " & rsMaterials("pricePer") & ""
    				rsPerMeasurementDetails.Open strPerMeasurementDetails, adoCon
    	
    				Set rsDeleteItem = Server.CreateObject("ADODB.Recordset")
    				strDeleteItem = "SELECT ID, createdBy, created, category, materials, supplier, pricePer, price, markup, updated, updatedBy, active FROM materials WHERE ID = " & rsMaterials("ID") & ""
    				rsDeleteItem.Open strDeleteItem, adoCon
    				%>
    					<div class="list-id">
    						<%=rsMaterials("ID")%>
    					</div>
    					<div class="list-category">
    						<%=rsCategoryDetails("title")%>
    					</div>
    					<div class="list-materials">
    						<%=rsMaterials("materials")%>
    					</div>
    					<div class="list-supplier">
    						<%=rsSupplierDetails("company")%>
    					</div>
    					<div class="list-price">
    						$<%=rsMaterials("price")%> <span class="grey-small">(<%=rsPerMeasurementDetails("title")%>)</span>
    					</div>
    					<div class="list-mark-up">
    						<%=rsMaterials("markUp")%>%
    					</div>
    					<div class="list-total-price">
    						$<%=formatNumber((((rsMaterials("price")/100)*rsMaterials("markUp"))+rsMaterials("price")),2)%>
    					</div>
    					<div class="list-edit">
    						<a href="materials.asp?itemEdit=<%=rsMaterials("ID")%>">Edit</a> | <a href="#" onclick="deleteItem()" style="cursor:auto">Delete</a>
    						<script>
    							function deleteItem()
    							{
    							var x;
    							var r=confirm("Are you sure your wish to delete this item?");
    							if (r==true)
    							  {
    							  x=window.location = "materials.asp?delete=<%=rsDeleteItem("ID")%>";
    							  }
    							else
    							  {
    							  x=window.location = "materials.asp"
    							  }
    							document.getElementById("demo").innerHTML=x;
    							}
    						</script>
    					</div>
    				<% rsMaterials.MoveNext 
    				End If
    				next %>
    thanks in advance to any one that can or will help.

  2. #2
    mark.shawe is offline Registered User
    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0
    Sorry, won't let me edit my post.

    I didn't explain my self very well...

    What I am trying to achieve is a list of items and delete button to remove an item, the javascript is a prompt box to confirm their decision to delete.

    x=window.location = "materials.asp?delete=<%=rsDeleteItem("ID")%>" ;
    this is the specific bit of the javascript that seems to fail as it gets the last records ID even though it is a loop and should get the current ID of the looped record.

    Hope this is a better explanation

  3. #3
    gk53's Avatar
    gk53 is offline Contributing User
    Join Date
    Mar 2005
    Location
    Columbus, OH
    Posts
    1,538
    Rep Power
    278
    You should have function outside of loop and it should be
    Code:
    function deleteItem( id)
    							{
    							var x;
    							var r=confirm("Are you sure your wish to delete this item?");
    							if (r==true)
    							  {
    							  x=window.location = "materials.asp?delete=" + id;
    							  }
    							else
    							  {
    							  x=window.location = "materials.asp"
    							  }
    							document.getElementById("demo").innerHTML=x;
    							}
    						</script>
    in this case your link to delete
    Code:
    <div class="list-edit">
    						<a href="materials.asp?itemEdit=<%=rsMaterials("ID")%>">Edit</a> | <a href="#" onclick="deleteItem('<%=rsMaterials("ID")%>')" style="cursor:auto">Delete</a>
    GK
    __________________________________________________ _____
    if you found this post is useful click Give Rep button (bottom side on this reply ) and agree

  4. #4
    mark.shawe is offline Registered User
    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0
    Perfect, thank you so much for me out, it was the perfect solution.

Share This Thread →

Become Part of This Conversation

Join NowFor Free!

Similar Threads

  1. Replies: 0
    Last Post: March 11th, 2011, 05:00 PM
  2. Convert JavaScript to VBScript (ASP Classic)
    By carrzkiss in forum HTML, JavaScript And CSS Help
    Replies: 0
    Last Post: February 8th, 2011, 06:27 AM
  3. Mix ASP Classic & JavaScript
    By omar_khanfer in forum ASP Development
    Replies: 3
    Last Post: January 6th, 2009, 12:06 AM
  4. Javascript form image replacement breaking in ASP classic
    By killfish in forum ASP Development
    Replies: 6
    Last Post: October 7th, 2007, 04:02 AM
  5. Javascript based Editor Compatible with Classic ASP?
    By Fatima in forum HTML, JavaScript And CSS Help
    Replies: 0
    Last Post: February 12th, 2007, 07:50 AM

ASP Free Advertisers and Affiliates