View Single Post
  #2 (permalink)  
Old 06-21-09, 11:02 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 2,726
Thanks: 0
Thanked 32 Times in 32 Posts
Quote:
so rather than going to a url i need it to run a javascript function
You didn't specify what javascript function you wanted to run or what the function is supposed to do.

Getting your script to run a function instead of the command location.href='url' is rather easy.

But I see that you are originally loading the location.href from a PHP function.
So I am a little confused as to what it is you are trying to accomplish.

But no matter, here is how you run a javascript function instead of a command.

Example:
HTML Code:
<html>
<head>
<script language="javascript">
function init_keyboard_events()
{
 if(document.all){document.onkeypress = handler;}
 else{window.onkeypress = handler;}
 }
 
function handler(e)
{
 var x = document.all ? window.event.keyCode : e.charCode;
 if(x == 119){do_something();}
 }
 
function do_something()
{
 alert("Doing something.");
 }
</script>
</head>
<body onload="init_keyboard_events();">
</body>
</html>
__________________
Jerry Broughton

Last edited by job0107; 06-21-09 at 11:06 PM.
Reply With Quote