Click to See Complete Forum and Search --> : ASP Integration with JavaScript


akrashdi
09-30-2003, 12:21 PM
Hi guys !


How can I assign a Database field content to a Javascript variable without using a text box as gateway.


Regards,
AKR

gil davis
09-30-2003, 01:07 PM
Write out a javascript in the HTML. For example, if your database data is in a variable named "dbData":
<script language="JavaScript" type="text/javascript">
var jsData = "<%=dbData%>";
</script>

Bullschmidt
09-30-2003, 11:30 PM
And here's a little more info about mixing server-side ASP (which gets processed first) with client-side JavaScript.

It's easy to use the value of a VBScript variable in JavaScript:
document.writeln('<%= MyVBScriptVariable %>');

Or here is an example which puts the value of a VBScript variable into a JavaScript alert box:
Response.Write "<script language='JavaScript'>alert('The value is " & MyVBScriptVariable & "');</script>"

But to send the value of a JavaScript variable to VBScript, well that's another story. You could have the JavaScript fill in a hidden form field and then post the form. That way VBScript can pick up the value of the hidden form field with Request.Form("MyFieldName")