dynamic html url in table data using jquery

Discussion in 'HTML & Website Design' started by xixo shah, Feb 20, 2015.

  1. #1
    I am new to jQuery. I have table contents displayed by jQuery using Bootstrap. I want to hyperlink for each value to be link to url. I don't know how to use Query to make table data as hyperlink , like www.mysite.com/deal/+run_accession+/pkg. I used [href= "www.google.com/" + run_accession> run_accession ] but this doesn't take run_accession parameter.

    <table id="resultsTable" class="table table-hover">
    <thead>
    <tr><th><input type="checkbox" id="selectAll" checked="true" \></th>
    <th class="sortable" sort-target="run_accession">Run</th>
    <th class="sortable" sort-target="experiment_accession">Experiment</th>

    </thead>
    <tbody id="results_display">
    {% for sra in sra_page %}
    <tr><td><input class="srasCb" checked="true" type="checkbox" name="sras" value="{{ sra.run_accession}}"\></td>
    <td>{{ sra.run_accession }}</td>
    <td>{{ sra.experiment_accession }}</td>
    </tr>
    {% endfor %}

    <script>
    var propagate_table = function(data) {
    $('#results_display').empty();

    for (i = 0; i < data.length; i++) {

    $('#results_display').append('<tr><td> <input class = "srasCb"'
    + checkboxSelection +' type="checkbox" name="sras" value="' + run_accession +'"\></td><td>'
    // I want to make <td> as link to url as: www.example.com/data.fields.run_accession
    + data.fields.run_accession; + '</td><td>'
    + data.fields.experiment_accession + '</td><td>'
    );
    }
    }
    </script>

    thanks
     
    xixo shah, Feb 20, 2015 IP
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #2
    Are you new to HTML as well? You don't make the TD a link, you put an anchor in the TD. Is there some reason you can't just go <a href=""></a> ?

    Though really you might want to throw jQuery and even JS in the trash until you have a firmer grasp on how to make a page like that work without scripting FIRST; remember the unwritten rule of JavaScript: "If you can't make the page work without scripting FIRST, you likely have no business adding scripting to it!"

    NOT that the fat bloated steaming pile of manure known as jQuery has any business on any website; particularly with the outdated outmoded garbage of sleazing out markup in the scripting instead of manipulating the DOM, made up fairy-tale "sort-target' bull making your output IE only, (and outdated legacy IE at that)...

    Nor is the mouth-breathing dumbass train wreck known as bootcrap much better. I'd highly suggest finding a stick to scrape that off with.

    Without seeing the data or what you are actually trying to accomplish it's hard to say much more.
     
    deathshadow, Feb 20, 2015 IP