Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

java script

Posted on 2012-03-26
1
Medium Priority
?
220 Views
Last Modified: 2012-06-21
wondering with simple Javascript function how to fetch with AJAX the file sample.html and Sort the contents of sample.html by price
sample.html
0
Comment
Question by:pal2k
1 Comment
 
LVL 38

Accepted Solution

by:
Tom Beck earned 2000 total points
ID: 37768145
Something like this?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>	
 <title>Untitled</title> 
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
</head>

<body>
    <input type="button" onclick="javascript:display()" value="display in order" />
    <div id="sampleHtml"></div>
<script type="text/javascript">
    $.ajaxSetup ({
		cache: false
	});
	var cities = new Array();
	var amts = new Array();
	$(document).ready(function(){
	    $.get('Sample.html', function(data) {
            $('#sampleHtml').html(data);
            $('#sampleHtml').find("div[id^='hotel_id']").each(function(){
                $(this).children('div').each(function(i){
                    if(i == 1){
                        amts.push($(this).find('span').text());
                    }else{
                        cities.push($(this).find('span').text());
                    }
                });
            });
        });
	});
function display(){
    var cityAmts = new Array();
    for(i=0; i<amts.length; i++){
        cityAmts[amts[i]] = cities[i];        
    }
    amts.sort(sortfunc);
    for(j=0; j<amts.length; j++){
        document.getElementById("sampleHtml").innerHTML += cityAmts[amts[j]] + ", " + amts[j]  +  '<br/>';
    }    
}
function sortfunc(a,b)
{
return a - b;
}
</script>
</body>
</html>

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question