Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

java script

Posted on 2012-03-26
1
Medium Priority
?
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

705 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