CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> ASP

 Passing an asp variable to html/javascript

Print topic Send  topic

Author Message
Damo

Posts: 22
Posted: 09/29/2008, 9:03 AM

Hi

I am having a major headache trying to pass an asp variable into html or javascript.

For testing purposes I can define a variable and use a javascript document.write to display the value, this only works when I define the variable in javascript.

What I am trying to do is for the javascript or html to read the value of my asp variable.

Can anyone help me please as I dont understad why it does not work and all I get on the page is 'Undefined'.

Here is my asp code: (I have inserted this in before show and on a button click - I get the same Undefined response.

Function Page_BeforeShow(Sender) 'Page_BeforeShow @1-A1547E8B

'Custom Code @16-73254650
' -------------------------
' Write your own code here.
' -------------------------
Dim TLImage

TLImage = "RedAmberGreen"

'End Custom Code

End Function 'Close Page_BeforeShow @1-54C34B28

Here is my javascript/html -

<script language="javascript">

var TLImage;
var colour1 = "purple";
var colour2 = "pink";
document.write('<p> colour1: ' + colour1 + '<br>colour2: ' + colour2 + '</p>');
document.write('<p> Traffic Light: ' + TLImage + '</p>');
document.write(TLImage);
</script>

It displays the pink and purple and for TLImage all I get is Undefined.

(The code is on the same page asp page)

Thanks in advance for your help.

Damo
View profile  Send private message
vinay

Posts: 2
Posted: 09/29/2008, 10:23 PM

Hi

<script language="javascript">

var TLImage;
var colour1 = "purple";
var colour2 = "pink";
document.write('<p> colour1: ' + colour1 + '<br>colour2: ' + colour2 + '</p>');
document.write('<p> Traffic Light: ' + <%=TLImage %>+ '</p>');
document.write(<%=TLImage%>);
</script>

should work.

Alternatively you could try using a hidden field and transfering the value as the default value, this can be read with javascript.
View profile  Send private message
Damo

Posts: 22
Posted: 10/01/2008, 8:33 AM

Hi vinay,

Unfortunately I still cannot get this working. Would you mind providing me with some code or a working example so I can understand how to achieve this please?

I assume if it reads the default value I can write an 'if then else' statement so I can change the value depending on the condition?

Thanks

Damo
View profile  Send private message
vinay

Posts: 2
Posted: 10/14/2008, 10:57 PM

Hi Damo,

Sorry for the late response,
below is a sample .asp for variable passing between asp and javascript
Hope this is still of use.

Regards
<html>
<body>
<%
'any asp variable definition could come here
session("valforTLImage") ="some text"
%>
<script type="text/javascript">
var TLImage;
TLImage = "<%=session("valforTLImage")%>";
var colour1 = "purple";
var colour2 = "pink";
document.write('<p> colour1: ' + colour1 + '<br>colour2: ' + colour2 + '</p>');
document.write('<p> Traffic Light: ' + TLImage + '</p>');
</script>

</body>
</html>


View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.