Solved

call javascript function in php

Posted on 2003-11-26
5
2,410 Views
Last Modified: 2011-10-03
i want to echo out a javascript function in php that disables different buttons across diferent forms

echo "<script>disable();</script>";

but it does not work

I know php is server side and js is client side, but when this line is echoed out, why does it not execute the js function?

thanks

0
Comment
Question by:zanner
  • 2
  • 2
5 Comments
 
LVL 11

Expert Comment

by:shmert
ID: 9827341
Most likely the disable() function isn't defined yet.  Moving the echo statement to the end of the page might fix it.
Download mozilla from http://mozilla.org and type javascript: in the URL bar, then open your page.
0
 

Author Comment

by:zanner
ID: 9827380
the function is defined in the head tag, before the call to the function
0
 
LVL 11

Expert Comment

by:shmert
ID: 9829540
can you view source in the browser and paste that in here?
0
 
LVL 1

Accepted Solution

by:
Hardaway earned 310 total points
ID: 9834682
In my understanding, client side script is always triggered by events. For those looks like auto running script is triggered by the javascript timer.

In your case, if you really want to run a javascript function after the HTML page has been delivered to the client, you should add a "onLoad" parameter inside the HTML <BODY> tag which calling your javascript function.

For example:
<body bgcolor=#FFFFFF link=#00ffff vlink=#00ffff alink=#00ffff onload="javascript:disable();">

You might define the javascript function disable() inside the <HEAD> scope like:
<HEAD>
<TITLE>My Title</TITLE>
<script language=JavaScript>
<!-- hide this script from non-javascript-enabled browsers
function disable() {
    // My code here....
}
// stop hiding -->
</script>
</HEAD>

Hope this can help!
0
 

Author Comment

by:zanner
ID: 9838703
I came to the same conclusion

I echo out the body tag with the js function in the onload attribute

a different function is placed in the onlaod att, depending on which button is pressed

thanks!

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

920 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

14 Experts available now in Live!

Get 1:1 Help Now