Title: Link formatting problem when concacting a variable
Last modified: August 21, 2016

---

# Link formatting problem when concacting a variable

 *  Resolved [cwizards](https://wordpress.org/support/users/cwizards/)
 * (@cwizards)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/link-formatting-problem-when-concacting-a-variable/)
 * I have been trying to build a list of items with an onClick event but the link
   keeps on formatting incorrectly! Can anyone advise how to correct this please.
   
   $name=$myrows->display_name; =”Fred Marshall” `echo "<UL><li><a onclick=$('#searchUsers').
   val('$name');>$name</a></li></ul>";` I have also tried `echo "<UL><li><a onclick
   =$('#searchUsers').val('" . $name . "');>$name</a></li></ul>";` with the same
   result :- `<a marshall');="" onclick="$('#acf-field-owner').val('16837');$('#
   searchUsers').val('Fred">Fred Marshall</a>` note the words Fred and Marshall 
   are not together in the val() function!

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/link-formatting-problem-when-concacting-a-variable/#post-4089884)
 * Is this code by any chance inside a shortcode handler? You cannot echo content
   from such a function. All content must be accumulated in a variable and returned.
   It’s the only reason I know of to get content chopped up like that.
 *  Thread Starter [cwizards](https://wordpress.org/support/users/cwizards/)
 * (@cwizards)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/link-formatting-problem-when-concacting-a-variable/#post-4089885)
 * Thanks for the suggestion, but I finally figured it out.
    I had not put \” around
   the onclick functions, adding them did the trick.
 * `echo "<UL><li><a onclick=\"$('#searchUsers').val('$name');\">$name</a></li></
   ul>";`
 *  Thread Starter [cwizards](https://wordpress.org/support/users/cwizards/)
 * (@cwizards)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/link-formatting-problem-when-concacting-a-variable/#post-4089887)
 * sorry, forgot to mark this as resolved

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Link formatting problem when concacting a variable’ is closed to new 
replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 3 replies
 * 2 participants
 * Last reply from: [cwizards](https://wordpress.org/support/users/cwizards/)
 * Last activity: [12 years, 9 months ago](https://wordpress.org/support/topic/link-formatting-problem-when-concacting-a-variable/#post-4089887)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
