Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    May 2005
    Posts
    215
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Is it possible to run ASP recordset in JS

    Hello all. I am trying to get the selection from a option list and compare it to a table in a database using onBlur. Here is what I have:

    Option List:

    Code:
    <select name="selCase" id="selCase" style="width: Auto; font:12px;" onmousedown="this.style.width=''" onChange="this.style.width='Auto'" onBlur="chkCode(this);" >
    JS function:

    Code:
    function chkCode(field) {
    
    var test2 = field.value
    	<% Dim oConn, oRS, sQry %>
    	<% Dim sConn %>
    	
    	<% set oConn = Server.CreateObject("ADODB.Connection") %>
    
    	<% sConn = MM_timesheet_STRING %>
    	<% oConn.Open sConn %>
    	<% 'Set oRS = Server.CreateObject("ADODB.Recordset") %>
    	<% Set oRS.ActiveConnection = oConn %>
    	
    	<% sQry = "SELECT Field1, Value1, Value2, color FROM tblCodes WHERE (Field1='Base_Billing' AND Value1='Case' AND Value2='" & test2 & "' AND color='#cc9999'); " %>
    	<% oRS.Open sQry %>
    	
    
    	<% If Not (oRS.BOF AND oRS.EOF) Then %>
    
    
    	alert ("It is EMPTY!");
    
    	<% 'Else %> 
    
    	alert ("It is FULL!");
    
    	<% 'End If %>
    }
    I want to know if the value selected has a color assigned to it in the database so I can give an Alert if it does.

    Is this even possible?

    Thanks in advance,

    Parallon

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    ASP is run on the server-side to generate HTML, CSS, and Javascript codes which will render/run on the client-side. By the time the page is rendered to the browser, the server-side codes have been executed. So you can't directly call ASP from Javascript. You have to submit the form in order for the server to get the selected item. You can also use AJAX so that the page won't refresh when a request is sent.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    Regular Coder
    Join Date
    May 2005
    Posts
    215
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Thank you for your quick response. So, would it be possible to have a recordset run on page load and put the results into an array, and then use JS to compare the option list value with the results of the array?

    Thanks,

    Parallon

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    There are many ways to solve your problem. The first 2 are the ones I suggested in my previous post. The 3rd one is:

    3. Load all the records and store them in javascript array. When a selection is made, look for the selected item in the array.

    The downside of this approach is if there are huge records, the page will load slowly. And if the data is updated frequently, the user might have old data loaded to the page. I recommend you to go through the AJAX solution.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #5
    Regular Coder
    Join Date
    May 2005
    Posts
    215
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Thank you. I will look into that.

    Parallon

  • #6
    Regular Coder
    Join Date
    May 2005
    Posts
    215
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Well, since I only have 21 records, I decided to go the route of an array. I have looked into AJAX before, but not sure if I am ready to tackle it yet. I couldn't figure out exactly how to get the RS results into a JS Array, but I did get them into an VBScript array. Will that work for what I am trying to do? If so, how do I go about comparing the string with the results of the array?

    Thanks,

    Parallon

  • #7
    Regular Coder
    Join Date
    May 2005
    Posts
    215
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Ok, I finally figured out the JS Array, so now all I need to do it to find a way to have a function compare a String to the items in the array and Alert if there is a match. What would I need to do or look into to make this happen?

    Thanks,

    Parallon

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    How are the array and the dropdown options set up? Pls post the generated Javascript and HTML code for that.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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