Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

call javascript function in php

Posted on 2003-11-26
5
Medium Priority
?
2,419 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 1240 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…
Suggested Courses

598 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