Solved

call javascript function in php

Posted on 2003-11-26
5
2,416 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

688 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