1

I have this print statement:

print "<a href='#' onClick='document.getElementById(\"myheader\").innerHTML=\"\"'".$rowQuery['keyword']."&nbsp; ·&nbsp;</a>";

Unfortunately, it prints:

<a ·&nbsp;="" keyword&nbsp;="" onclick="document.getElementById("myheader").innerHTML=""" href="#"/>

I have no idea why, any help would be useful. Because of the way it is printed, I can't see anything on the screen and the functionality does not work either.

Note ($rowQuery['keyword'] = "keyword" in this case so it is being evaluated, that is not the problem. The problem is that it prints it weird)

(When I use HTML instead of php to print it using this line:

<a href="#" onClick="document.getElementById('myheader').innerHTML=''">ALL</a>

it works completely fine)

7
  • Prints weird? As in, the attributes print out-of-order? Commented Jun 20, 2010 at 7:11
  • Yes, as you can see, it prints weirdly in different order which means it doesn't function at all (i mean that I can't see what should be printed on the screen and of course the javascript line does not work either Commented Jun 20, 2010 at 7:13
  • I doubt it actually prints like that. I bet the browser you're debugging it in shows you a DOM representation, not the actual source. Commented Jun 20, 2010 at 7:14
  • I am using firebug on firefox. However, the problem is, I can't see it on the screen, if I print it normally (I mean HTML and not print it through PHP it works completely fine) Commented Jun 20, 2010 at 7:15
  • 1
    There is no closing tag in your first print statement. try this: print "<a href='#' onClick='document.getElementById(\"myheader\").innerHTML=\"\"'".$rowQuery['keyword'].">ALL</a>"; Commented Jun 20, 2010 at 7:18

3 Answers 3

4

You're missing a closing > for the opening <a> element, and maybe there are other syntax issues I'm not spotting right now. The browser is interpreting it as best he can, which ends up being weird.

To minimize problems like this (and avoid lots of quote escaping), leave the static text static and only echo the dynamic content like this:

<a href="#"><?php echo $rowQuery['keyword']; ?></a>
Sign up to request clarification or add additional context in comments.

Comments

2

You will get a more accurate picture of what's getting written to PHP's output stream by viewing source instead of FireBug.

Your code doesn't appear to be closing the <a> tag. It also looks like there's an extended character · between your non-breaking spaces. You should make sure that it is supported in your character set or replace it with a HTML entity, such as &#8226;. If you must use extended characters, it's generally advisable to make sure that your PHP script, your HTML meta tags and your PHP server encoding config setting are all referring to the same character set or one stray extended character can kill your page when getting rendered in the browser. If you stick to UTF-8 for everything, you are likely to have the fewest problems (though not always).

Comments

0

I think you are missing the closure of the <a... tag

You have:<a href=... some description</a>

Instead of <a href=... >some description</a>

Try something like this (not sure I got the location of the '>' correct:

print "<a href='#' onClick='document.getElementById(\"myheader\").innerHTML=\"\"'".$rowQuery['keyword']">."&nbsp; ·&nbsp;</a>";

Comments

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.