...

View Full Version : Is it possible to run ASP recordset in JS



parallon
06-14-2007, 04:59 PM
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:


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

JS function:


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

glenngv
06-14-2007, 05:13 PM
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 (http://www.w3schools.com/ajax/ajax_intro.asp) so that the page won't refresh when a request is sent.

parallon
06-14-2007, 05:18 PM
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

glenngv
06-14-2007, 05:34 PM
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.

parallon
06-14-2007, 06:09 PM
Thank you. I will look into that.

Parallon

parallon
06-15-2007, 05:58 PM
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

parallon
06-15-2007, 07:17 PM
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

glenngv
06-15-2007, 07:29 PM
How are the array and the dropdown options set up? Pls post the generated Javascript and HTML code for that.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum