Solved

Run Javascript without an event

Posted on 2003-10-29
3
206 Views
Last Modified: 2008-03-03
Hi  All,

Is it possible to run a javascript funtion without assigning it to an event? for example, conditionally in an if statement as in the example below.

If somevariable = somevalue then

call javascriptfunction()

else

continue page

End if

or does anyone know of an alternative way to automatically run some javascript based on a condition.

Thanks in advance,
Nev.

0
Comment
Question by:dobermannnn
  • 2
3 Comments
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 9643445
You can do this:

<body onLoad="<% if x=something then%>javascriptfunction()<%end if%>" >

FtB
0
 
LVL 42

Expert Comment

by:frodoman
ID: 9644057
If you can tie to the onload event, use f_t_b's example ^^^.  Otherwise, it's messy, but you can directly output the javascript:

<%
IF some_condition THEN
   response.write("<script language='JavaScript'>")
   response.write("var x=" & x & ";")
   (continue jscript)
   response.write("</script>")
ELSE
   (do other stuff)
END IF
%>
0
 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 20 total points
ID: 9644105
Frodman has that right:

consider the following:

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY>

<P>&nbsp;</P>
<SCRIPT LANGUAGE=javascript>
<!--
alert("hi");
//-->
</SCRIPT>

</BODY>
</HTML>


So, we know that works (try it!). The next step then would be:

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY>
<%if someCondition then%>
<SCRIPT LANGUAGE=javascript>
<!--
alert("hi");
//-->
</SCRIPT>
<%end if%>
</BODY>
</HTML>
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question