KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Passing 4D variables into JavaScript
PRODUCT: 4D | VERSION: 6.5 | PLATFORM: Mac & Win
Published On: August 31, 2001
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

Normally, 4D does not parse JavaScript code for 4D tags when sending an HTML page. However, you might want to use the values of some 4DVAR tags in your JavaScript code.

Here's a way to do this using hidden HTML form inputs:


<head>

<script type="text/javascript" language="Javascript">

Blah blah blah in JavaScript

myWin = window.open(document.forms[0].link.value+'/4DACTION/Gen4D_SendHelp/'+param,"Help",winParams)

Other Blah Blah Blah in JavaScript

</script>

</head>


<body BACKGROUND="/images/busbackground3.gif">

<Form name="form">

<input type="hidden" name="link" value="<!--4DVAR CGI4D_t_4DLINK-->"></form>

Blah Blah Blah in HTML

</Body>


I can't use the 4DVAR tag directly in my JavaScript code, so instead I'm going to replace it with another variable reference which is:


document.forms[0].link.value


In my HTML page, I just need to declare a form with a variable named 'link' which contains the value I need assigned via a 4DVAR tag. 4D will replace the 4DVAR tag with the real value and then it can be accessed by referring to the form input value using regular JavaScript syntax.