• Resolved cwizards

    (@cwizards)


    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

    (@bcworkz)

    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

    (@cwizards)

    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

    (@cwizards)

    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.