php file with javascript functions?

jimmy

New member
Trying to teach myself some basic web programming fundamentals. Can anyone tell me why this doesn't work? The alert window doesn't appear when the update link is clicked. (This is not my actual code, but is formatted the same. I just left out the stuff specific to the website)

<?php
session_start();

if (!$_SESSION["valid_user"])
{
// User not logged in, redirect to login page
header("Location: login.php");
}


?>
<!--Yes, I am correctly logged in, and my session variables have been set, so I do see this page.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My Title</title>


<script type="text/javascript">

var this;
var that;
var someotherstuff = new Stuff();

function update()
{
alert ("In function update");
//function code not required for question
}
//other functions omitted

</script>
</head>
<body>

<div id="links">
<a href="#" onClick="javascript:update()" id="updateLink">Update</a>
</div>

</body>
</html>
The doctype appears to have been cut off for some reason. It is done correctly in my actual code.
In response to the first 2 suggestions, I used the firefox error console and it claims that update is not defined. I do have another page formatted exactly the same way where the links that run javascript functions work fine. The only difference is that this one is a php file due to the script at the top to check for login. Does that have anything to do with it?
And I did take out the javascript: but it still doesn't work. The other file which does work does have the "javascript:", so I don't think that matters.
@Bjarki Ágúst Nope. Still update is not defined. It's as if update is not in <head>. Except it is.
Some food for thought. Function gets called on page load but never again.
Problem fixed. On to another one. A syntax error in the function was messing up the browser's ability to recognize that it was a function. I did something that works in java but apparently not javascript. Lesson learned. The function now gets called. Thanks everyone for your help.
 
Back
Top