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
Solved

java script

Posted on 2012-03-26
1
214 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 500 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how can i get 4 nd 5 ? 3 31
Access RV042 GUI / Browser Issues 25 48
Add or delete table rows 10 53
Is there a way to bind the ID to the text value of the search result? 28 52
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

856 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