Jump to content

Single and Double Quotes in Anchors with Javascript issue.


njdubois

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.