Solved

Run Javascript without an event

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

792 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