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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie how to display a variable

Status
Not open for further replies.

BuilderSpec

Programmer
Dec 24, 2003
383
GB
Hi

I have some ASP pages that do simple stuff.

<%
Dim i

i = 4

%>
.
.
.
<%=i%>

How would i translate this to javascript ?

I have got :

<script>

function GetInfo()
{
var i=4;
document.write(i)
}
</script>

But how do i call this function in the middle of my page ? I want the page to say something like


Amount Available : 4 ( where the 4 comes from the script etc )


PS Know it's a simple example it's the principle i am after.

Thanks

Have looked on net but all examples seem to call functions as a result of button presses. i just want simple variable substitution like ASP but in JAVASCRIPT

Any help appreciated thanks






Hope this helps!

Regards

BuilderSpec
 
Such as this.
[tt]
<html>
<head>
<script type="text/javascript">
function GetInfo()
{
var i=4;
document.write(i)
}
</script>
</head>
<body>
<div>some div</div>
<div>This div pick up a value of <script>GetInfo()</script>.<div>
<div>other div</div>
</body>
<html>
[/tt]
But since you show a particular curiosity in this kind of "document.write()" in analogy to response.write, some notes of warning are in order.
[1] You are relying on a very thin time slot of linear (ordering of) loading of html script client-side; its foundation - the linearity - may be shaky in many circumstances.
[2] The function lost general usage: after used during the page loading up, its utility is practically lost. Server side response.write will not re-appear in the client-side and hence does not consume memeory and bandwidth.
[3] Mis-use/abuse of document.write often shows up in novice javascripters.
 
How would i translate this to javascript ?

Are you wanting to convert your VBScript server-side ASP to server-side JavaScript, or to client-side JavaScript?

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
What i really really want...

i have some asp pages and i want to implement a floating menu which is great it works fine when i use the scripting in a .htm page. However most of my pages are .asp pages and the floating menu seems to stop working ( the menu is displayed ok but does not move ).

So i thought if i could somehow change from a .asp page to .htm i could translate all my asp code to scripting. The question i would really like to know is how can i get my floating menu to work with a .asp page ?


I have got this code from which is exactly what i need but i need it to work in a page that is asp not htm ? possible ?




<script>
if (!document.layers)
document.write('<div id="divStayTopLeft" style="position:absolute">')
</script>

<layer id="divStayTopLeft">

<!--EDIT BELOW CODE TO YOUR OWN MENU-->
<table border="1" width="130" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" bgcolor="#FFFFCC">
<p align="center"><b><font size="4">Menu</font></b></td>
</tr>
<tr>
<td width="100%" bgcolor="#FFFFFF">
<p align="left"> <a href=" Drive</a><br>
<a href=" New</a><br>
<a href=" Hot</a><br>
<a href=" <a href=" Zone</a></td>
</tr>
</table>
<!--END OF EDIT-->

</layer>


<script type="text/javascript">

/*
Floating Menu script- Roy Whittle (Script featured on/available at This notice must stay intact for use
*/

//Enter "frombottom" or "fromtop"
var verticalpos="frombottom"

if (!document.layers)
document.write('</div>')

function JSFX_FloatTopDiv()
{
var startX = 3,
startY = 150;
var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
function ml(id)
{
var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
if(d.layers)el.style=el;
el.sP=function(x,y){this.style.left=x;this.style.top=y;};
el.x = startX;
if (verticalpos=="fromtop")
el.y = startY;
else{
el.y = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
el.y -= startY;
}
return el;
}
window.stayTopLeft=function()
{
if (verticalpos=="fromtop"){
var pY = ns ? pageYOffset : document.body.scrollTop;
ftlObj.y += (pY + startY - ftlObj.y)/8;
}
else{
var pY = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
ftlObj.y += (pY - startY - ftlObj.y)/8;
}
ftlObj.sP(ftlObj.x, ftlObj.y);
setTimeout("stayTopLeft()", 10);
}
ftlObj = ml("divStayTopLeft");
stayTopLeft();
}
JSFX_FloatTopDiv();
</script>



Hope this helps!

Regards

BuilderSpec
 
The script should run identically regardless of the page extension. It could be .asp, .apsx, .cfm, .php, .htm, .html, or even .wibbblyBibblyBoo if your server is so configured... but it should still work.

If it runs with .htm but not with .asp, chances are the error is not with your script, but something else you have on your ASP page that you don't have on your HTML version of the same page, such as a conflicting 'onload' event handler, etc.

Dan





Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I have taken a brief look at the script. It is obviously wrong and results in nesting <div><script></div></script>.

Move the documet.write of </div> either up or way down. For instance, move up.
[tt]
<!-- etc etc -->
</layer>

[red]if (!document.layers)
document.write('</div>')[/red]

<script type="text/javascript">
//etc etc...
//Enter "frombottom" or "fromtop"
var verticalpos="frombottom"

[red]//[/red]if (!document.layers)
[red]//[/red]document.write('</div>')

function JSFX_FloatTopDiv()
{
//etc etc...
}
JSFX_FloatTopDiv();
</script>
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top