Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBscript in Java Script - understand variables

Status
Not open for further replies.

JennB

Programmer
Feb 3, 2002
29
CA
HI,

I am new to Java Script and am trying to incorporate it into my asp page so that when a user clicks on a dynamic list box, the information for the item they clicked on appears in text boxes. I can make all of the lines in the following function work except the fact that the vbscript does not seem to recognize articleid in the select statement. Any ideas? Thanks for your help. Note that below the script for the function is the code for the list box.


function Fillboxes()
{
articleid = document.frmArticles.select.value
<%
set GetArticle = Server.CreateObject(&quot;ADODB.Recordset&quot;)
GetArticle.ActiveConnection = MM_enerchihealth_STRING
GetArticle.Source = &quot;SELECT * FROM dbo.tblArticle where fldArticleNum = &quot; & articleid
GetArticle.CursorType = 0
GetArticle.CursorLocation = 2
GetArticle.LockType = 3
GetArticle.Open()
GetArticle_numRows = 0
%>
document.frmInsert.txtTitle.value = &quot;<%=(GetArticle.Fields.Item(&quot;fldTitle&quot;).Value)%>&quot;;
}

</SCRIPT>


'This is the code for the list box:

<select name=&quot;select&quot; size=&quot;6&quot; onClick=&quot;Fillboxes()&quot;>
<%
While (NOT GetArticles.EOF)
%>
<option value=&quot;<%=(GetArticles.Fields.Item(&quot;fldArticleNum&quot;).Value)%>&quot;><%=(GetArticles.Fields.Item(&quot;fldTitle&quot;).Value)%></option>
<%
GetArticles.MoveNext()
Wend
If (GetArticles.CursorType > 0) Then
GetArticles.MoveFirst
Else
GetArticles.Requery
End If
%>
 
Can you place a 'response.write &quot;ArticleID: &quot; &articleid' after
GetArticle_numRows = 0 ?

When you reload the page and view source do you see the string
&quot;ArticleID: 1&quot; ?? _______________________________________________
OutsideIntranets.com
Stop wasting time, get to work
 
No, the string does not show up. It's as if once you enter the <% %> signs, articleid is not recognized.
 
JennB,

For this to work, you need the VBSCript code to reside outside of the JavaScript, because VB is rendered serverside and JS is rendered client side.

I would suggest somethign along these lines....
1) execute VB first, even if you are looking for a list of id's back...
2) write javascript to incorporate VBScript values from query

Once the public variable is set in VB, you can inspect it with JS, meaning get the articleIDs back from the query, then when setting up the multi-drop down, have JS inspect the variable to see if it is an array, if so....do multiple <option value> pairs.

Hope that lead you well

JP

<%
execute VBScript to retrieve data
%>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
function JSfunction()
{
articleid=<%=articleid%>

}

</SCRIPT> _______________________________________________
OutsideIntranets.com
Stop wasting time, get to work
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top