Dzherzinsky Posted August 25, 2011 Share Posted August 25, 2011 Hello everybody There is one word here that I dont get to include the right way, I think because of the issue of single and double quotes. When I replace the variable by its value, it works me alright, but since I have to include this PHP variable ($user) within the onclick JS function, it is problematic. <?php echo ' <form> <input type="checkbox" name="asset" value="" onclick="getLoggedInUser($user) " /> I am potentially interested in this product service<br /> <div id="txtHint"><b>Note:</b></div> </form> '; By the way, I cant believe the verification code to submit the text. It took me 2 minutes to figure out what they were talking about John, George, Paul, and I had no idea what the hell that was, when I casually thought of the Beatles. so Ringo. I hate that rubbish music. Next time I get verification code like that I go elsewhere. Quote Link to comment https://forums.phpfreaks.com/topic/245694-onclick-event-with-php-2-lines-one-word/ Share on other sites More sharing options...
Adam Posted August 25, 2011 Share Posted August 25, 2011 Variables between single-quotes are not parsed. Concatenate the value: [...] onclick="getLoggedInUser(' . $user . ') " [...] Although unless $user is numeric, you're going to get a parse error in your JavaScript as you don't have quotes around the parameter value. If that's the case try: [...] onclick="getLoggedInUser(\'' . $user . '\') " [...] Ain't pretty, but neither's inline JS Quote Link to comment https://forums.phpfreaks.com/topic/245694-onclick-event-with-php-2-lines-one-word/#findComment-1261919 Share on other sites More sharing options...
Dzherzinsky Posted August 25, 2011 Author Share Posted August 25, 2011 @Adam Thank you very much! it worked and thanks for the tip about being numeric, I have no problem in turning $user to $user_id so that is numeric. That code snippet is part of an AJAX code. I was forced to do a weird thing like this because in my System the only way to get the user_id was through the built in PHP function get_userID() of my system (a social network) and then I would be inserting that data into the JS. Naturally I would have written 'this.value' if I were getting the IDs, say from a Select box but it had to locate the user_id, thanks God (and to you!) it worked, I was beginning to dread that my idea risking client server with client side languages would hate to talk to each other, but it did the trick Best regards Quote Link to comment https://forums.phpfreaks.com/topic/245694-onclick-event-with-php-2-lines-one-word/#findComment-1261930 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.