I want to echo the url which includes an onlick property. Here is my code below:

function royal_sidebutton_body_tag_html() {

    // get plugin option array and store in a variable
    $royal_sidebutton_plugin_option_array   = get_option( 'royal_sidebutton_plugin_options' );

    // fetch individual values from the plugin option variable array
    $royal_sidebutton_text_for_tab          = $royal_sidebutton_plugin_option_array[ 'text_for_tab' ];
    $royal_sidebutton_tab_url               = /*$royal_sidebutton_plugin_option_array[ 'tab_url' ]; */ 'https://www.example.co.uk">';
    $royal_sidebutton_target_blank          = $royal_sidebutton_plugin_option_array[ 'target_blank' ];

    // set the page target
    if ($royal_sidebutton_target_blank == '1') {
        $royal_sidebutton_target_blank = ' target="_blank"';
    }

    // Write HTML to render tab
    echo '<a href="' . esc_url( $royal_sidebutton_tab_url ) . '"' . $royal_sidebutton_target_blank . '><div id="royal_sidebutton_tab" class="royal_sidebutton_contents royal_sidebutton_left">' . esc_html( $royal_sidebutton_text_for_tab ) . '</div></a>';
}

I have tried to add

a href="//www.example.co.uk/login.aspx" target="_blank" title="Login" onclick="popitup(); return false;"

to the variable "$royal_sidebutton_tab_url" but it does not work. It just adds it to the link.

Hi,
As per my understanding your requirment is when you click on link you get href url

HTML
<a href="//www.example.co.uk/login.aspx" target="_blank" title="Login" onclick="popitup(); return false;">Click</a>

Javascript:
on popitup() function pass 'this' object i.e. onclick="popitup(this)" ;
and in the function get href value
ex: Javascript Function

function popitup(thisobj) {
    var thisurl = thisobj.attr('href');
    alert('Url is: ' + thisurl);
}

Please check and let me know.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.