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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.