Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Reply
 
LinkBack Thread Tools Display Modes
Old 09-01-2011, 06:12 PM   #1 (permalink)
Broken In
 
sganesh's Avatar
 
Join Date: Nov 2007
Location: Chennai
Posts: 113
Default How to sort html table values using select box


hi ,
In below code,How to sort html table column values based values selected in select box.
The html content s
<html>
<body>

Sort by<select>
<option>Name</option>
<option>Surename</option>
<option>Age</option>
</select>

<table border="1" class="" width="400">
<thead>
<tr>
<th>Name</th>
<th>Surename</th>
<th>Age</th>
</tr>
</thead>

<tbody>
<tr >
<td >John1</th>
<td >Smith1</th>
<td >30</th>
</tr>
<tr >
<td >John2</th>
<td >Smith2</th>
<td >31</th>
</tr>
<tr >
<td >John3</th>
<td >Smith3</th>
<td >32</th>
</tr>
<tr >
<td >John4</th>
<td >Smith4</th>
<td >33</th>
</tr>
<tr >
<td >John5</th>
<td >Smith5</th>
<td >34</th>
</tr>
<tr >
<td >John</th>
<td >Smith</th>
<td >35</th>
</tr>
<tr >
<td >John</th>
<td >Smith</th>
<td >36</th>
</tr>
<tr >
<td >John</th>
<td >Smith</th>
<td >37</th>
</tr>
</tbody>

</table>

</body>
</html>

Is the problem can be solved in javascript?
sganesh is offline   Reply With Quote
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 09-01-2011, 06:44 PM   #2 (permalink)
XLr8
 
arpanmukherjee1's Avatar
 
Join Date: Sep 2008
Posts: 637
Default Re: How to sort html table values using select box

the answer to ur ques is -- yes.

but first i'd like to give some tips

1. please indent ur code. specially HTML. makes it lot more readable
2. if it was indented always use
Code:
this is CODE tag
.
3. please google up the topic before posting it here.
4. if u did look it up. give reference and tell why it didnt solve ur issue

now for ur answer:
Javascript table sorting script
JavaScript Toolbox - Sortable Table

if u want to sort only through the dropdown. extract the function from the script and use it on button click that would be just adjacent to the dropdown
__________________
Quote:
There are more things in heaven and earth, Horatio,
Than are dreamt of in your philosophy.
arpanmukherjee1 is offline   Reply With Quote
Old 09-01-2011, 08:23 PM   #3 (permalink)
Broken In
 
sganesh's Avatar
 
Join Date: Nov 2007
Location: Chennai
Posts: 113
Default Re: How to sort html table values using select box

thanks for the info
i ve used sortable js found in
Sortable Table (WebFX)
the code s as follows,But didnt work.
Could someone help me in fixing this issue.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>

<script type="text/javascript" src="js/sortabletable.js"></script>

<script type="text/javascript">

var st2 = new SortableTable(document.getElementById("table-2"),
["String", "String", "Number"]);


function alertselected(selectobj){

if(selectobj.selectedIndex.valueOf()=="1")
{
alert(st2.sort(0))

}

if(selectobj.selectedIndex.valueOf()=="2")
{
st2.sort(1)
}
if(selectobj.selectedIndex.valueOf()=="3")
{
st2.sort(2)

}


}
</script>




</head>
<body>

<form id="someform">
<select id="mymenu" size="1" onChange="alertselected(this)">
<option value="nothing" selected="selected">Select a Sort</option>
<option>Name</option>
<option>Surename</option>
<option>Age</option>
</select>
</form>
<table class="sort-table" cellspacing="1" cellpadding="2" border="1" id="table-2" width="400">
<thead>
<tr>
<th>Name</th>
<th>Surename</th>
<th>Age</th>
</tr>
</thead>

<tbody>
<tr >
<td >John1</th>
<td >Smith1</th>
<td >30</th>
</tr>
<tr >
<td >John2</th>
<td >Smith2</th>
<td >31</th>
</tr>
<tr >
<td >John3</th>
<td >Smith3</th>
<td >32</th>
</tr>
<tr >
<td >John4</th>
<td >Smith4</th>
<td >45</th>
</tr>
<tr >
<td >John5</th>
<td >Smith5</th>
<td >34</th>
</tr>
<tr >
<td >John</th>
<td >Smith</th>
<td >35</th>
</tr>
<tr >
<td >John</th>
<td >Smith</th>
<td >36</th>
</tr>
<tr >
<td >John</th>
<td >Smith</th>
<td >37</th>
</tr>
</tbody>

</table>

</body>
</html>
sganesh is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Charan
- by Charan

Advertisement




All times are GMT +5.5. The time now is 03:25 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2