Click to See Complete Forum and Search --> : Passing variables to javascript


taurz
10-30-2003, 01:53 AM
I have the following query

rs.Open "SELECT refer.ref FROM refer WHERE (refer.ID = (select max(ID) from refer))", conn

the result set returns only a single value

Now how is it possible for me to pass this value to a javascript code in the same page?

Is it possible to value to the next page?

thanks

TaurZ

rdoekes
10-30-2003, 08:30 AM
This could work like this:

<%
dim intVar
rs.Open "SELECT 1...", cnn
intVar = rs.Field(0).Value
rs.Close
%>
<SCRIPT language="javascript">
var myVar = <% = intVar%>;
</SCRIPT>

Afterwards you can do what you want with the variable in javascript.

Hope this helps,

-Rogier Doekes

taurz
11-02-2003, 03:38 AM
i used it this way..



function calc(){
var myVar = <% = intVar%>
var typd = ""
d = new Date()
m = d.getMonth() + 1
y = d.getYear()
x = document.f.type.value
n = document.f.typeno.value

var referanceNo = "AIC/" + x + "/" + y + "/" + m + "/" + n + myVar;



the intVar is defined in the ASP part as u said... but it gives an error in the script part. if i remove the ASP variables in the script, it works fine.

plz help