This is my code: PHP code: $a = '<a href="test.php">test</a> $data=<<<data <a id="ciButton" onmouseup="bMouseUp('$a')" onmouseover="bMouseOver()" onmouseout="bMouseOut()" style="color:#CC0000;">Click Me.</a> data; echo($data); Code (markup): It echos something like this: <a href="test.php">test</a>a')" onmouseover="bMouseOver()" onmouseout="bMouseOut()" style="color:#CC0000;">Click Me.</a> //this code is printed to the page Code (markup): I need it to not echo out the html code. I need to to parse the html and print that. This is for a button which will show the $a html if pressed not the $a html code. Please help! I've been going an hour at this to no avail. Thanks.
$a = '<a href="test.php">test</a>'; $data = "<a id=\"ciButton\" onmouseup=\"bMouseUp('{$a}');\" onmouseover=\"bMouseOver();\" onmouseout=\"bMouseOut();\" style=\"color:#CC0000;\">Click Me.</a>"; echo $data; PHP:
Did you test it because it isn't working for me? Prints out: test');" onmouseover="bMouseOver();" onmouseout="bMouseOut();" style="color:#CC0000;">Click Me. Code (markup): I think that the glitch has something to do with the " marks because when I remove them it works just fine. Anyone know how I can fix this? Thanks.
$a ="<a href=\"test.php\">test</a>"; $data="<a id=\"ciButton\" onmouseup=\"bMouseUp('{$a}')\" onmouseover=\"bMouseOver()\" onmouseout=\"bMouseOut()\" style=\"color:#CC0000;\">Click Me.</a>"; echo $data; PHP: or you could try $data="<a id=\"ciButton\" onmouseup=\"bMouseUp('".$a."')\" onmouseover=\"bMouseOver()\" onmouseout=\"bMouseOut()\" style=\"color:#CC0000;\">Click Me.</a>"; PHP: That should work though it looks alot like krsix's code. Anywho i do not see any errors with it.
oh right, you have to escape what's in the $a for js it does echo out, javascript just didn't parse it. do what tyler gave
Is it a php or a js issue? Try $a = '<a href="test.php">test</a>'; $data = "<script type=\"text/javascript\">var a = '{$a}';</script><a id=\"ciButton\" onmouseup=\"bMouseUp(a);\" onmouseover=\"bMouseOver();\" onmouseout=\"bMouseOut();\" style=\"color:#CC0000;\">Click Me.</a>"; PHP:
woah gonna get technical on me . So i noticed your signature, how did you manage to get 300k ip's. Also i do think imozeb is working with a template thus the code is not working correctly. Think of the way glype's template works, its kind of the same.
It is a php issue. I am not working with a template. I used <<< just as an easy way of storing alot of my html code in a php variable. What I'm trying to do is create a <a> tag which when pressed triggers a javascript code to show some text inside the <a> tag. It needs to be echo'd out from PHP because I am using PHP to validate some variables with a database before echoing out the proper values. I have all the javascript and extra php code complete. Now I am just trying to get PHP to echo out the proper data. But php won't echo it out properly. It seems that when PHP encounters a double quote it messes up the javascript in the <a> tag. When I test the codes you gave me I pasted it into its own file (without any other code) for testing to see if it just printed out the text within the <a> tag but it didn't. Could someone test the code and see if they can get it to work because I still can't figure it out? $a ="<a href=\"test.php\">test</a>";$data="<a id=\"ciButton\" onmouseup=\"bMouseUp('{$a}')\" onmouseover=\"bMouseOver()\" onmouseout=\"bMouseOut()\" style=\"color:#CC0000;\">Click Me.</a>"; echo $data; PHP: Thank you. P.S. from my hour or so of troubleshooting I found that the quotes in the $a variable were the problem though I can't seem to get it to work even with escaping them?
replace your html quotes with " or just look up the ascii version http://www.ascii.cl/htmlcodes.htm
Try this.., and tell me. $a ="<a href=\"test.php\">test</a>"; $data="<a id=\"ciButton\" onmouseup=\"bMouseUp('{"$a"}')\" onmouseover=\"bMouseOver()\" onmouseout=\"bMouseOut()\" style=\"color:#CC0000;\">Click Me.</a>"; echo $data; PHP:
Seems you have tried all sorts... When passing the data from php to js, I would not use your method. Instead, I would output all relevant data either in xml form (ie using DOM) or transferring values directly to js as object. I assume the information you want to pass can crudely be broken down to tag=a&link=http://www.link-to-my-url.com/&linktext=my link text Code (markup): so while i output to DOM, the code looks like <div id="ciButtonData" style="display: none;"> <span id="tag"><?php echo "a"; ?></span> <span id="link"><?php echo "http://www.link-to-my-url.com/"; ?></span> <span id="linktext"><?php echo htmlentities( "my link text" ); ?></span> </div> <a id="ciButton" href="javascript:void(0)" onmouseup="bMouseUp( document.getElementById( this.id+"Data" ) )" onmouseout="bMouseOut()" style="color: #c00"> Click Me </a> // in this case, the function bMouseUp takes care of getting data // from the Dom Element passed and assembling the element if necessary. HTML: alternately, you can also have <a id="ciButtonData" style="display: none;" href="<?php echo "http://www.link-to-my-url.com/"; ?>"> <?php echo htmlentities( "my link text" ); ?> </a> <a id="ciButton" href="javascript:void(0)" onmouseup="bMouseUp( document.getElementById( this.id+"Data" ) )" onmouseout="bMouseOut()" style="color: #c00"> Click Me </a> // in this case, the function bMouseUp( element ) takes care of getting data // from the invisible a tag, by using // element.href & element.textContent HTML: using js object you can do the same by: <script> var ciButtonData = { link: <?php echo "http://www.link-to-my-url.com/"; ?>, linktext: <?php echo htmlentities("my link text"); ?> }; </script> <a id="ciButton" href="javascript:void(0)" onmouseup="bMouseUp( ciButtonData )" onmouseout="bMouseOut()" style="color: #c00"> Click Me </a> HTML: further, i am not pretty sure, what are you doing with the bMouseUp( arg ) function. But I am sure, you will be able to ply it to your needs.
Thanks everyone and thanks bvraghav. Your DOM suggestion reminded my of a way I used to transfer html to javascript which is very similar to what you suggested. Thanks!