-1

i want to pass a variable through to a php on an onClick event, it doesn't seem to be passing it through to the page properly though.

Here's my html

<a href="data.php" onClick="video(We Have a Pope)" hidefocus="">

and the relevant javascript function

function video(result) {
  $('#information').load('data.php?result=' + result);
  document
}

My php page looks like this

<?php

$result = $_GET['result'];
echo $result;
?>

Nothing is being outputted though :S

1
  • onClick="video('We Have a Pope')" Commented Mar 29, 2012 at 7:29

4 Answers 4

3

onClick="video(We Have a Pope)" should be onClick="video('We Have a Pope')"

1
  • You can easily tell by this site's syntax highlighting, where the error is. :-) Commented Mar 29, 2012 at 7:54
1

You need quotation marks when you pass string as parameter, like this:

<a href="data.php" onClick="video('We Have a Pope')" hidefocus="">
1
<a href="data.php" onClick="javascript:video('We Have a Pope');" hidefocus="">
2
  • You don't need a javascript:-pseudo URI for the onclick attribute. Commented Mar 29, 2012 at 8:00
  • In that context, it isn't a URI, the javascript: part is a label Commented Mar 29, 2012 at 8:04
0
onClick="video('We Have a Pope');"

or

onClick="video(\"We Have a Pope\");"
1
  • `\` is not an HTML escape character. Why are you adding a label when there is no loop? Commented Mar 29, 2012 at 8:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.