Solved

Run Javascript without an event

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

12 Experts available now in Live!

Get 1:1 Help Now