Solved

Run Javascript without an event

Posted on 2003-10-29
3
208 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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 …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

685 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