Solved

call javascript function in php

Posted on 2003-11-26
5
2,413 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

785 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