Solved

Run Javascript without an event

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 …
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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now