/    Sign up×
Community /Pin to ProfileBookmark

calling a javascript function from php

Hello,
I have a javascript function that i want to call and it is in a js file. What i want is to call that function from a php tag.
<?php
….
if( $row_count > 0)
{
echo “<script language=’javascript’ SRC=’javascripts/AddSubjectAndOrganization.js’>disableNextAndPreviousButtons(‘This is the message’)</script>”;
}
?>

But the function disableNextAndPreviousButtons never gets called. I have a alert(“Hello”) in the function but the alert never pops up in the html page calling the function.

I have seen on various forums that we can call a javascript function from a php piece of code if we echo it, but nothing ever happens.

What am i doing wrong?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@TecBratAug 01.2011 — The issue is that PHP is processed before the browser ever gets the page. JS is executed by the browser. You can have PHP echo some JS to set variables and then use the onload event to deal with the variables that you have set.
×

Success!

Help @ofilha spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...