0

Does anyone know if this is possible?

I have a javascript which highlights the table row when a user hovers down it. it now also links to a page when you click it. but i want to add php to my link. Can it be done?

I have attempted it myself but it gives me this error: Parse error: syntax error, unexpected '"', expecting T_STRING

<script>
 $(function() {
 $('tr').hover(function() {
 $(this).css('background-color', '#eee');
 $(this).contents('td').css({'border': '0px solid red', 'border-left': 'none', 'border-right': 'none'});
 $(this).contents('td:first').css('border-left', '0px solid red');
 $(this).contents('td:last').css('border-right', '0px solid red');
 },
 function() {
 $(this).css('background-color', '#FFFFFF');
 $(this).contents('td').css('border', 'none');
 $('tr').click(function() { 
 document.location = <?php \"read_message.php?msg={$inbox[0]}\">{$inbox['subject']}"; ?>';
} );
 });
 });
 </script>
asked Oct 25, 2012 at 16:02
2
  • before <?php add a ' you aren't opening it. but you are also closing something else after ['subject']}" with a " Commented Oct 25, 2012 at 16:04
  • yea tried that still getting same error. Parse error: syntax error, unexpected '"', expecting T_STRING Commented Oct 25, 2012 at 16:08

3 Answers 3

1

You are getting parser error because $inbox['subject'] may contain some apostrophe's that are breaking the string opening and closing apostrophes.

Try using the below:

document.location = "<?php echo "read_message.php?msg={$inbox[0]}>{$inbox['subject']}" ?>";
answered Oct 25, 2012 at 16:09
Sign up to request clarification or add additional context in comments.

1 Comment

That's true, try to keep in mind "clean inputs, filter outputs" (or clean inputs, escape outputs if you prefer)
1

try

document.location = <?php echo '"read_message.php?msg='.$inbox[0].'">'.$inbox['subject'] ; ?>

or

 document.location = "read_message.php?msg=<?php echo $inbox[0]; ?>"><?php echo $inbox['subject'].'"'; ?>';
answered Oct 25, 2012 at 16:03

1 Comment

there's still an unmatched ' at the end
0

document.location = '<?php echo \"read_message.php?msg={$inbox[0]}\">{$inbox['subject']}"; ?>';

answered Oct 25, 2012 at 16:04

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.