njdubois Posted March 27, 2013 Share Posted March 27, 2013 I'm trying to make an HTML menu using PHP, Javascript and AJAX, but I'm having problems formatting my code. The problem boils down to the use of single and double quotes. If I do it this way: $menu_item='<a href="javascript:change_menu(menu_1);">Home</a><br />'; Console says menu_1 is not defined, which makes since. This way, I am passing menu_1 like it is an object. If I try : $menu_item='<a href="javascript:change_menu("menu_1");">Home</a><br />'; The Console now says: Uncaught SyntaxError: Unexpected end of input And I can't use: $menu_item="<a href="javascript:change_menu('menu_1');">Home</a><br />"; OR $menu_item='<a href="javascript:change_menu('menu_1');">Home</a><br />'; Because then PHP thinks I'm breaking the string apart, and it gives me an error. And I know I can't use: $menu_item='<a name="menu_1" href="javascript:change_menu(this.name);">Home</a><br />'; You see what I am trying to do. What am I doing wrong? This is truly confusing me! Any guidance would be greatly appreciated! Thanks Nick Quote Link to comment Share on other sites More sharing options...
njdubois Posted March 27, 2013 Author Share Posted March 27, 2013 Nevermind! Solved it! <a name="menu_1" href="javascript:;" onclick="change_menu(this.name);">Home</a> Thanks anyways! Quote Link to comment Share on other sites More sharing options...
haku Posted March 29, 2013 Share Posted March 29, 2013 You should change that to this: <a href="#" name="menu_1" onclick="change_menu(this.name);">Home</a> 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.