Home › Forums › JavaScript › Show detail page onClick
- This topic is empty.
-
AuthorPosts
-
July 29, 2013 at 10:43 am #145056
boyjarv
ParticipantHi,
Below, I have 2 functions: getAllDetails() and getDetails(id) My first function “getAllDetails()” works fine, this returns a list. I would now like to add the ability to be able to click on a list item and pass through the ‘trackid’ to get to the details page?
Please help, I am almost there…
` function getAllDetails() { var myTable = ” ; myTable += ‘</p>
<ul class=”ui-listview” data-role=”listview”>’ ;
var url = “http://www.trialsevolution.co.uk/mobileapp/json-example2.php”; $.getJSON(url, function(json) { i=1; $.each(json, function(k, v) {
myTable += “<li data-corners=’false’ data-shadow=’false’ data-iconshadow=’true’ data-wrapperels=’div’ data-icon=’arrow-r’ data-iconpos=’right’ data-theme=’c’ class=’ui-btn ui-btn-icon-right ui-li-has-arrow ui-li ui-btn-up-c’><div class=’ui-btn-inner ui-li’><div class=’ui-btn-text’><a href='”+v.trackid+”‘>”+v.trackname+”</a></div><span> </span></div></li>”;
});
myTable += ‘</ul><p>’ ; $(“#stud_tbl”).html(myTable) ;</p>
<pre><code> });
</code></pre><p>}</p>
<p>function getDetails(id) { var myTable = ” ; var id_val = id.value;</p>
<p>var url = “http://www.trialsevolution.co.uk/mobileapp/json.php?id=”+id_val; $.getJSON(url, function(json) { var select = $(‘#city-list’); $.each(json, function(k, v) {<br /> myTable += “</p>
<ul>
<li>”+v.trackname+”</li>
<li>”+v.trackcreator+”</li>
</ul><p>”;<br /> }); $(“#stud_tbl”).html(myTable) ;</p>
<pre><code> });
</code></pre><p>}</p>
<p>`
August 1, 2013 at 9:38 pm #145447thechrisroberts
ParticipantI’m not real clear what you’re trying to do, but – you’re presenting a list based on JSON data. You want the user to be able to click a list item in order to see the details.
In the code you have above, you already have
a href="etc" ...etc...
but that’s not really what you’re wanting? So you’re wanting something where they can click the link and have it display the details on that same page, not actually redirecting them to another page or somewhere offsite? In that case, you should use something like onclick rather than href:a onclick="getDetails(' + v.trackid + ')"...etc...
Update inline example didn’t work; edited my reply to show markup
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.