Chotor Posted June 16, 2008 Share Posted June 16, 2008 Hi. This is probably an easy request, but I never received my "PHP and MySQL programming" book from the bookstore, so I'm doing it by trial and error. This is the code I'm trying to send back to the html page. return " <a href=javascript:myfunction('".$k."'); style=\"font-size: ".$s."%; color:#99cfec; cursor:pointer \">".$k."</a> "; However, if I have a $k with spaces, the value will break off at the first whitespace. For instance, having $k="John Wayne" will output javascript:myfunction('John (The strange thing is that font-size, color, cursor, and the second $k is output correctly) I'm guessing it has something to do with htmlentities and/or encoding text for html, but I'm not sure. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 16, 2008 Share Posted June 16, 2008 First of all, I'd use printf() or sprintf() in this situation because it's neater. But other than that...it just cuts off the rest of the code, or just the JS function input? Quote Link to comment Share on other sites More sharing options...
webent Posted June 16, 2008 Share Posted June 16, 2008 I don't know if this helps, but here is a bit of code that I wrote for ya that can show one way of passing vars into javascript, there are other ways though, you can pass them through the function itself... <script language="javascript" type="text/javascript"> <!-- function testFunction(form) { var $testVariable = form.testVariable.value; alert($testVariable); return false; } // --> </script> <? $k="John Wayne" ?> <form name="test_form" action="" method="POST" onSubmit="return testFunction(this)"> <input type="text" name="testVariable" value="John Wayne"> <input type="submit" name="submit_button" value="Test Me"> </form> Quote Link to comment Share on other sites More sharing options...
Chotor Posted June 16, 2008 Author Share Posted June 16, 2008 First of all, I'd use printf() or sprintf() in this situation because it's neater. But other than that...it just cuts off the rest of the code, or just the JS function input? It cuts off the JS function. The statusbar in FireFox (showing the current target) shows only that. I think the function and html is properly sent from php and recieved to html. It's just the browser's rendering that breaks things.. I don't know if this helps, but here is a bit of code that I wrote for ya that can show one way of passing vars into javascript, there are other ways though, you can pass them through the function itself... Thanks. I'll look at that tomorrow. Quote Link to comment Share on other sites More sharing options...
Chotor Posted June 20, 2008 Author Share Posted June 20, 2008 Here's what it looks like. Mouse is hovering over "Rosemary Harris" Quote Link to comment Share on other sites More sharing options...
Chotor Posted June 20, 2008 Author Share Posted June 20, 2008 Here is a part of the response sent by PHP and recieved by the browser: <a href=javascript:MYFUNCTION('Ron Perlman'); style="font-size: 100%; color:#99cfec; cursor:pointer ">Ron Perlman</a> <a href=javascript:MYFUNCTION('Rosemary Harris'); style="font-size: 100%; color:#99cfec; cursor:pointer ">Rosemary Harris</a> <a href=javascript:MYFUNCTION('Rupert Evans'); style="font-size: 100%; color:#99cfec; cursor:pointer ">Rupert Evans</a> Note that the html is intact. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.