You are viewing limited content. For full access, please sign in.

Question

Question

Help in changing the link name value from the url to a name

asked on April 17, 2023

Hello.  We are pulling a url from a sql table into a forms table using a lookup rule.  The url is clickable using javascript.  We are trying to change the visible portion of the link with a simple quote number which is available in a 2nd column of the same table.  (Normally this is hidden)

We have a single table with css class myTable.  Inside are two columns with css class urlColumn and nameColumn.

The javascript allows the urlColumn value to be clickable and open.  We are looking for help on adjusting the script to allow the nameColumn value to be displayed instead of the full url value.  And yet, when it is clicked, it will open the url.

 

$(document).ready(function() {
  // select all rows in the table with class "myTable"
  $('.myTable').on('click','.urlColumn input',function() {
    // get the value from the "nameColumn" of the current row
    var name = $(this).find('.nameColumn').text();
    // get the URL from the "urlColumn" of the current row
    var url = $(this).find('.urlColumn').text();
    // create a new anchor tag with the URL replaced by the value from the "nameColumn"
    var link = $('<a></a>').attr('href', name).text(name);
    // replace the contents of the "urlColumn" with the new anchor tag
    $(this).find('.urlColumn').html(link);
  });
});

 

0 0

Replies

replied on April 17, 2023

Sounds like you just need to use two variables to create the hyperlink. Its not entirely clear what your variables are and what is working/expected code. So below is a snippet you should be able to apply to your code.

 

    // get the value from the "nameColumn" of the current row
    var name = $(this).find('.nameColumn').text();
    // get the URL from the "urlColumn" of the current row
    var url = $(this).find('.urlColumn').text();
    // create a new anchor tag with the URL replaced by the value from the "nameColumn"
    var link = $('<a></a>').attr('href', url).text(name);
    // replace the contents of the "urlColumn" with the new anchor tag
    $(this).find('.urlColumn').html(link);

The link element has two key attributes you should supply to do what you want. The href defines the link to open, and the inner text defines what is shown to the user for the clickable portion of the link.

 

Ref: https://www.w3schools.com/html/html_links.asp

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.