How to redirect on another page and pass parameter in url from table?


How to redirect on another page and pass parameter in url from table ? I've created in tornato template something like this

<table data-role="table" id="my-table" data-mode="reflow">
        {% for result  in players %}
            <td><input type="button" name="theButton" value="Detail"
    {% end %}

and I would like when I press detail to be redirect on /player_detail?username=username and show all detail about that player. I tried with href="javascript:window.location.replace('./player_info');" inside input tag but don't know how to put result['username'] in. How to do this ?

This question is tagged with javascript jquery templates jquery-mobile tornado

~ Asked on 2012-12-31 10:48:04

The Best Answer is


Set the user name as data-username attribute to the button and also a class:


<input type="button" name="theButton" value="Detail" class="btn" data-username="{{result['username']}}" />


$(document).on('click', '.btn', function() {

    var name = $(this).data('username');        
    if (name != undefined && name != null) {
        window.location = '/player_detail?username=' + name;


Also, you can simply check for undefined && null using:

$(document).on('click', '.btn', function() {

    var name = $(this).data('username');        
    if (name) {
        window.location = '/player_detail?username=' + name;

As, mentioned in this answer

if (name) {            

will evaluate to true if value is not:

  • null
  • undefined
  • NaN
  • empty string ("")
  • 0
  • false

The above list represents all possible falsy values in ECMA/Javascript.

~ Answered on 2012-12-31 11:41:12


Do this :

<script type="text/javascript">
function showDetails(username)
   window.location = '/player_detail?username='+username;

<input type="button" name="theButton" value="Detail" onclick="showDetails('username');">

~ Answered on 2012-12-31 10:52:47

Most Viewed Questions: