Solved

java script

Posted on 2012-03-26
1
211 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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now