views:

46

answers:

3

Hi,

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)

A: 

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>";

RonK
+3  A: 

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>
deceze
+2  A: 

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).

Andrew