0

someone please help. i wanted to use "requestID" javascript variable on my script block and use it to my sql query. but when i do it,its not working.

requestID= aReqId[iSelReq];
<%
    Dim sqlQuery 
    Dim sqlQuery2
    Dim sRecords
    Dim sRecords2
    Dim iVersion1   
    Dim iFieldSeqId2
    Dim vValue
    Dim iNumofReqTypes
    Dim iLoop


    for iLoop=0 to iNumofReqTypes

        sqlQuery = "SELECT iVersion, iFieldSeqId FROM tblUsrAcntFieldsDtlMst, tblReqTypeMst WHERE tblReqTypeMst.ireqTypeID = tblUsrAcntFieldsDtlMst.iSysid and iSysID = '509' and iversion = (select max(iVersion) from tblUsrAcntFieldsDtlMst where iSysID = '509')  and cReqDisable = 'N' order by iFieldSeqId,ixCoordinate, iYCoordinate"

        sRecords = getRecords(sqlQuery,bResult)
        if bResult then
            iVersion1 = sRecords(0,iLoop)
            iFieldSeqId2 = sRecords(1,iLoop)
        end if 
        sqlQuery2 = "select vValues from tblNewUsrAcntReqDtlTxn where iReqID = " & requestID &"   and iSysID = " & SysID &" and iVersion = " & iVersion & " and iFieldSeqID = " & iFieldSeqId & ""
        bResult = false
        sRecords2 = getRecords(sqlQuery2,bResult)
        if bResult then
            vValue = sRecords2(0,0)
        end if 
    next                        


%>  
3
  • Define "it's not working". What did you expect it to work and what does it actually do? Commented Jul 28, 2012 at 9:13
  • when i include those codes, my page doesn't show anything,but when i exclude it or define an exact value for "requestid" on my sql query.it works Commented Jul 28, 2012 at 9:16
  • Can you show us how your page actually talks to the server? It looks like you may have a form that does a POST? Is that right? Could you show us the HTML for the form? And how and when you set the JavaScript variable? Commented Jul 28, 2012 at 10:04

2 Answers 2

1

I think you're missing some basic things here. I guess this is a part of a .asp page.

Javascript is client-side language, which means that the Javascript code is parsed and executed bu the browser that loads the page. The VB part is a server-side language, so it's executed by the server. Client and server are two different worlds. You cannot directly use the requestID variable in your server-side code because it's known only in the client-side part.

So, if you want to know the value of that variable, you must first send its value to the server. There are a couple of ways to do so... posting the form, via AJAX... Then there's must be a listener on the server-side to receive that value and store it in the current session. Then you can use it in your VB code.

Sign up to request clarification or add additional context in comments.

Comments

1

You cannot use a client-side variable in your server-side code. You can, however, use a server-side variable in the client-side code, because the server-side code executes first.

You could use Javascript's AJAX here to make a call to your Classic ASP page, with the variable data, get the database results, and then post the results back to the page.

A Tip

In your example, you can do away with sqlQuery and sqlQuery2 and just use the one. The same with sRecords and sRecords2, just have the one. There is no need to fill two variables for each of those tasks. It won't make much difference in a small loop like that, but it's good practice to save code & resource.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.