Solved

call javascript function in php

Posted on 2003-11-26
5
2,408 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
Comment Utility
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
Comment Utility
the function is defined in the head tag, before the call to the function
0
 
LVL 11

Expert Comment

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

Accepted Solution

by:
Hardaway earned 310 total points
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

763 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

6 Experts available now in Live!

Get 1:1 Help Now